mirror of
https://github.com/scottbez1/smartknob.git
synced 2025-11-04 17:19:40 +08:00
Fine tuning for esp32s3 (#143)
- exposed strain SCK and DO - use 12 bit PWM (instead of 16 bit) for screen brightness on s3 - added option to use uart serial for s3 - bump nanopb/Nanopb @ 0.4.7 - fixed SPI bus alias and DMA channel for s3 --------- Co-authored-by: Scott Bezek <scottbez1@gmail.com>
This commit is contained in:
parent
370b8ca92b
commit
8700af8a24
7
.github/workflows/pio.yml
vendored
7
.github/workflows/pio.yml
vendored
@ -60,3 +60,10 @@ jobs:
|
||||
run: |
|
||||
pio run \
|
||||
-e nanofoc
|
||||
|
||||
- name: Build Firmware (brushknight_esp32s3)
|
||||
# Run regardless of other build step failures, as long as setup steps completed
|
||||
if: always() && steps.pio_install.outcome == 'success'
|
||||
run: |
|
||||
pio run \
|
||||
-e brushknight_esp32s3
|
||||
|
||||
@ -35,9 +35,9 @@ void DisplayTask::run() {
|
||||
tft_.setRotation(SK_DISPLAY_ROTATION);
|
||||
tft_.fillScreen(TFT_DARKGREEN);
|
||||
|
||||
ledcSetup(LEDC_CHANNEL_LCD_BACKLIGHT, 5000, 16);
|
||||
ledcSetup(LEDC_CHANNEL_LCD_BACKLIGHT, 5000, SK_BACKLIGHT_BIT_DEPTH);
|
||||
ledcAttachPin(PIN_LCD_BACKLIGHT, LEDC_CHANNEL_LCD_BACKLIGHT);
|
||||
ledcWrite(LEDC_CHANNEL_LCD_BACKLIGHT, UINT16_MAX);
|
||||
ledcWrite(LEDC_CHANNEL_LCD_BACKLIGHT, (1 << SK_BACKLIGHT_BIT_DEPTH) - 1);
|
||||
|
||||
spr_.setColorDepth(8);
|
||||
|
||||
@ -201,7 +201,7 @@ QueueHandle_t DisplayTask::getKnobStateQueue() {
|
||||
|
||||
void DisplayTask::setBrightness(uint16_t brightness) {
|
||||
SemaphoreGuard lock(mutex_);
|
||||
brightness_ = brightness;
|
||||
brightness_ = brightness >> (16 - SK_BACKLIGHT_BIT_DEPTH);
|
||||
}
|
||||
|
||||
void DisplayTask::setLogger(Logger* logger) {
|
||||
|
||||
@ -262,7 +262,7 @@ void InterfaceTask::run() {
|
||||
Wire.setClock(400000);
|
||||
#endif
|
||||
#if SK_STRAIN
|
||||
scale.begin(38, 2);
|
||||
scale.begin(PIN_STRAIN_DO, PIN_STRAIN_SCK);
|
||||
#endif
|
||||
|
||||
#if SK_ALS
|
||||
|
||||
@ -12,6 +12,10 @@
|
||||
#include "serial/uart_stream.h"
|
||||
#include "task.h"
|
||||
|
||||
#ifndef SK_FORCE_UART_STREAM
|
||||
#define SK_FORCE_UART_STREAM 0
|
||||
#endif
|
||||
|
||||
class InterfaceTask : public Task<InterfaceTask>, public Logger {
|
||||
friend class Task<InterfaceTask>; // Allow base Task to invoke protected run()
|
||||
|
||||
@ -26,7 +30,7 @@ class InterfaceTask : public Task<InterfaceTask>, public Logger {
|
||||
void run();
|
||||
|
||||
private:
|
||||
#ifdef CONFIG_IDF_TARGET_ESP32S3
|
||||
#if defined(CONFIG_IDF_TARGET_ESP32S3) && !SK_FORCE_UART_STREAM
|
||||
HWCDC stream_;
|
||||
#else
|
||||
UartStream stream_;
|
||||
|
||||
@ -51,7 +51,13 @@ void MT6701Sensor::init() {
|
||||
.quadhd_io_num = -1,
|
||||
.max_transfer_sz = 1000,
|
||||
};
|
||||
|
||||
#ifdef CONFIG_IDF_TARGET_ESP32S3
|
||||
esp_err_t ret = spi_bus_initialize(SPI3_HOST, &tx_bus_config, SPI_DMA_CH_AUTO);
|
||||
#else
|
||||
esp_err_t ret = spi_bus_initialize(HSPI_HOST, &tx_bus_config, 1);
|
||||
#endif
|
||||
|
||||
ESP_ERROR_CHECK(ret);
|
||||
|
||||
spi_device_interface_config_t tx_device_config = {
|
||||
@ -70,7 +76,12 @@ void MT6701Sensor::init() {
|
||||
.pre_cb=NULL,
|
||||
.post_cb=NULL,
|
||||
};
|
||||
#ifdef CONFIG_IDF_TARGET_ESP32S3
|
||||
ret=spi_bus_add_device(SPI3_HOST, &tx_device_config, &spi_device_);
|
||||
#else
|
||||
ret=spi_bus_add_device(HSPI_HOST, &tx_device_config, &spi_device_);
|
||||
#endif
|
||||
|
||||
ESP_ERROR_CHECK(ret);
|
||||
|
||||
|
||||
|
||||
112
platformio.ini
112
platformio.ini
@ -29,7 +29,7 @@ lib_deps =
|
||||
infineon/TLV493D-Magnetic-Sensor @ 1.0.3
|
||||
bxparks/AceButton @ 1.9.1
|
||||
bakercp/PacketSerial @ 1.4.0
|
||||
nanopb/Nanopb @ 0.4.6 ; Ideally this would reference the nanopb submodule, but that would require
|
||||
nanopb/Nanopb @ 0.4.7 ; Ideally this would reference the nanopb submodule, but that would require
|
||||
; everyone to check out submodules to just compile, so we use the library
|
||||
; registry for the runtime. The submodule is available for manually updating
|
||||
; the pre-compiled (checked in) .pb.h/c files when proto files change, but is
|
||||
@ -86,12 +86,16 @@ build_flags =
|
||||
-DPIN_MT_CSN=14
|
||||
-DPIN_LED_DATA=7
|
||||
-DPIN_LCD_BACKLIGHT=19
|
||||
-DPIN_STRAIN_DO=38
|
||||
-DPIN_STRAIN_SCK=2
|
||||
|
||||
-DDESCRIPTION_FONT=Roboto_Thin_24
|
||||
-DDESCRIPTION_Y_OFFSET=20
|
||||
-DVALUE_OFFSET=30
|
||||
-DDRAW_ARC=0
|
||||
|
||||
-DSK_BACKLIGHT_BIT_DEPTH=16
|
||||
|
||||
; TFT_eSPI setup
|
||||
-DUSER_SETUP_LOADED=1
|
||||
-DGC9A01_DRIVER=1
|
||||
@ -184,3 +188,109 @@ build_flags =
|
||||
|
||||
; Reduce loop task stack size (only works on newer IDF Arduino core)
|
||||
; -DARDUINO_LOOP_STACK_SIZE=2048
|
||||
|
||||
|
||||
[env:brushknight_esp32s3]
|
||||
extends = base_config
|
||||
platform = espressif32@6.3.1
|
||||
board = esp32-s3-devkitc-1
|
||||
board_build.partitions = default_ffat.csv
|
||||
|
||||
monitor_speed = 115200
|
||||
|
||||
lib_deps =
|
||||
${base_config.lib_deps}
|
||||
bodmer/TFT_eSPI@2.5.0
|
||||
fastled/FastLED @ 3.5.0
|
||||
bogde/HX711 @ 0.7.5
|
||||
adafruit/Adafruit VEML7700 Library @ 1.1.1
|
||||
askuric/Simple FOC@2.3.0
|
||||
|
||||
build_flags =
|
||||
${base_config.build_flags}
|
||||
; Use physical UART for the serial stream rather than the S3 default USB CDC
|
||||
-DSK_FORCE_UART_STREAM=1
|
||||
-DMONITOR_SPEED=115200
|
||||
; Display enabled: 1=enable, 0=disable
|
||||
-DSK_DISPLAY=1
|
||||
; PWM bit resolution (even esp32s3 claims that there are 13 bits, max is 12, after it panics)
|
||||
-DSK_BACKLIGHT_BIT_DEPTH=12
|
||||
; Display orientation: 0=usb bottom, 2=usb top
|
||||
-DSK_DISPLAY_ROTATION=0
|
||||
; LEDs enabled: 1=enable, 0=disable
|
||||
-DSK_LEDS=1
|
||||
; Number of LEDs
|
||||
-DNUM_LEDS=8
|
||||
; Strain-gauge press input enabled: 1=enable, 0=disable
|
||||
-DSK_STRAIN=1
|
||||
; Ambient light sensor (VEML7700) enabled: 1=enable (display/LEDs match ambient brightness), 0=disable (100% brightness all the time)
|
||||
-DSK_ALS=0
|
||||
; Use MT6701 magnetic encoder
|
||||
-DSENSOR_MT6701=1
|
||||
; Invert direction of angle sensor (motor direction is detected relative to angle sensor as part of the calibration procedure)
|
||||
-DSK_INVERT_ROTATION=1
|
||||
|
||||
-DMOTOR_WANZHIDA_ONCE_TOP=1
|
||||
|
||||
; Pin configurations
|
||||
; Motor
|
||||
-DPIN_UH=20
|
||||
-DPIN_UL=19
|
||||
-DPIN_VH=21
|
||||
-DPIN_VL=17
|
||||
-DPIN_WH=12
|
||||
-DPIN_WL=18
|
||||
|
||||
-DPIN_BUTTON_NEXT=-1
|
||||
-DPIN_BUTTON_PREV=-1
|
||||
-DPIN_LED_DATA=7
|
||||
-DPIN_LCD_BACKLIGHT=5
|
||||
|
||||
-DPIN_SDA=15
|
||||
-DPIN_SCL=8
|
||||
|
||||
-DPIN_MT_DATA=37
|
||||
-DPIN_MT_CLOCK=13
|
||||
-DPIN_MT_CSN=14
|
||||
|
||||
-DPIN_STRAIN_DO=38
|
||||
-DPIN_STRAIN_SCK=1
|
||||
|
||||
-DDESCRIPTION_FONT=Roboto_Thin_24
|
||||
-DDESCRIPTION_Y_OFFSET=20
|
||||
-DVALUE_OFFSET=30
|
||||
-DDRAW_ARC=0
|
||||
|
||||
; TFT_eSPI setup
|
||||
-DUSER_SETUP_LOADED=1
|
||||
-DGC9A01_DRIVER=1
|
||||
-DCGRAM_OFFSET=1
|
||||
-DTFT_WIDTH=240
|
||||
-DTFT_HEIGHT=240
|
||||
-DTFT_MISO=-1 # fake
|
||||
-DTFT_MOSI=3
|
||||
-DTFT_SCLK=4
|
||||
-DTFT_CS=9
|
||||
-DTFT_DC=2
|
||||
-DTFT_RST=6
|
||||
-DTFT_BL=-1
|
||||
-DLOAD_GLCD=1
|
||||
-DLOAD_GFXFF=1
|
||||
-DSPI_FREQUENCY=40000000
|
||||
|
||||
; Reduce loop task stack size (only works on newer IDF Arduino core)
|
||||
; -DARDUINO_LOOP_STACK_SIZE=2048
|
||||
|
||||
-DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_DEBUG
|
||||
|
||||
; FastLED setup
|
||||
; Modify the default unusable pin mask to allow GPIO 7 (allowed to use on ESP32-PICO-V3-02)
|
||||
; Unusable bits: 6, 8, 9, 10, 20
|
||||
; (0ULL | _FL_BIT(6) | _FL_BIT(8) | _FL_BIT(9) | _FL_BIT(10) | _FL_BIT(20))
|
||||
-DFASTLED_UNUSABLE_PIN_MASK=0x100740LL
|
||||
; 0~39 except from 24, 28~31 are valid
|
||||
; (0xFFFFFFFFFFULL & ~(0ULL | _FL_BIT(24) | _FL_BIT(28) | _FL_BIT(29) | _FL_BIT(30) | _FL_BIT(31)))
|
||||
-DSOC_GPIO_VALID_GPIO_MASK=0xFF0EFFFFFF
|
||||
; GPIO >= 34 are input only
|
||||
; (SOC_GPIO_VALID_GPIO_MASK & ~(0ULL | _FL_BIT(34) | _FL_BIT(35) | _FL_BIT(36) | _FL_BIT(37) | _FL_BIT(38) | _FL_BIT(39)))
|
||||
-DSOC_GPIO_VALID_OUTPUT_GPIO_MASK=0x30EFFFFFF
|
||||
|
||||
Loading…
Reference in New Issue
Block a user