Cleanup and lots of moved files
This commit is contained in:
parent
701c33a8a5
commit
d69c54af21
412 changed files with 450 additions and 156 deletions
5
.gitignore
vendored
Normal file
5
.gitignore
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
build
|
||||
main/build
|
||||
sdkconfig.old
|
||||
*.bak
|
||||
*.old
|
28
.gitmodules
vendored
28
.gitmodules
vendored
|
@ -1,24 +1,24 @@
|
|||
[submodule "esp-idf"]
|
||||
path = esp-idf
|
||||
url = https://github.com/espressif/esp-idf.git
|
||||
[submodule "factory_test/components/bus-i2c"]
|
||||
path = factory_test/components/bus-i2c
|
||||
[submodule "components/bus-i2c"]
|
||||
path = components/bus-i2c
|
||||
url = git@github.com:Nicolai-Electronics/esp32-component-bus-i2c.git
|
||||
[submodule "factory_test/components/i2c-pca9555"]
|
||||
path = factory_test/components/i2c-pca9555
|
||||
[submodule "components/i2c-pca9555"]
|
||||
path = components/i2c-pca9555
|
||||
url = git@github.com:Nicolai-Electronics/esp32-component-i2c-pca9555.git
|
||||
[submodule "factory_test/components/i2c-bno055"]
|
||||
path = factory_test/components/i2c-bno055
|
||||
[submodule "components/i2c-bno055"]
|
||||
path = components/i2c-bno055
|
||||
url = git@github.com:Nicolai-Electronics/esp32-component-i2c-bno055.git
|
||||
[submodule "factory_test/components/spi-ili9341"]
|
||||
path = factory_test/components/spi-ili9341
|
||||
[submodule "components/spi-ili9341"]
|
||||
path = components/spi-ili9341
|
||||
url = git@github.com:Nicolai-Electronics/esp32-component-spi-ili9341.git
|
||||
[submodule "factory_test/components/spi-ice40"]
|
||||
path = factory_test/components/spi-ice40
|
||||
[submodule "components/spi-ice40"]
|
||||
path = components/spi-ice40
|
||||
url = git@github.com:Nicolai-Electronics/esp32-component-spi-ice40.git
|
||||
[submodule "factory_test/components/sdcard"]
|
||||
path = factory_test/components/sdcard
|
||||
[submodule "components/sdcard"]
|
||||
path = components/sdcard
|
||||
url = git@github.com:Nicolai-Electronics/esp32-component-sdcard.git
|
||||
[submodule "factory_test/components/pax-graphics"]
|
||||
path = factory_test/components/pax-graphics
|
||||
[submodule "components/pax-graphics"]
|
||||
path = components/pax-graphics
|
||||
url = https://github.com/robotman2412/pax-graphics.git
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
cmake_minimum_required(VERSION 3.5)
|
||||
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
|
||||
project(main)
|
||||
|
|
@ -1 +1,2 @@
|
|||
# MCH2022 firmware for ESP32
|
||||
# Factory test firmware
|
||||
|
||||
|
|
1
build.sh
1
build.sh
|
@ -7,5 +7,4 @@ export IDF_PATH="$PWD/esp-idf"
|
|||
export IDF_EXPORT_QUIET=0
|
||||
source "$IDF_PATH"/export.sh
|
||||
|
||||
cd factory_test
|
||||
idf.py build
|
||||
|
|
|
@ -1,11 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
set -e
|
||||
set -u
|
||||
|
||||
export IDF_PATH="$PWD/esp-idf"
|
||||
export IDF_EXPORT_QUIET=0
|
||||
source "$IDF_PATH"/export.sh
|
||||
|
||||
cd efuse
|
||||
idf.py build
|
2
clean.sh
2
clean.sh
|
@ -7,6 +7,4 @@ export IDF_PATH="$PWD/esp-idf"
|
|||
export IDF_EXPORT_QUIET=0
|
||||
source "$IDF_PATH"/export.sh
|
||||
|
||||
cd factory_test
|
||||
idf.py clean
|
||||
|
||||
|
|
|
@ -7,8 +7,6 @@ export IDF_PATH="$PWD/esp-idf"
|
|||
export IDF_EXPORT_QUIET=0
|
||||
source "$IDF_PATH"/export.sh
|
||||
|
||||
cd factory_test
|
||||
|
||||
if [ "$#" -eq 2 ]; then
|
||||
idf.py $2 -p $1
|
||||
else
|
||||
|
|
14
components/mch2022-bsp/CMakeLists.txt
Normal file
14
components/mch2022-bsp/CMakeLists.txt
Normal file
|
@ -0,0 +1,14 @@
|
|||
idf_component_register(
|
||||
SRCS "hardware.c" "rp2040.c"
|
||||
INCLUDE_DIRS "."
|
||||
REQUIRES
|
||||
"appfs"
|
||||
"bus-i2c"
|
||||
"i2c-bno055"
|
||||
"i2c-pca9555"
|
||||
"pax-graphics"
|
||||
"renze-graphics"
|
||||
"sdcard"
|
||||
"spi-ice40"
|
||||
"spi-ili9341"
|
||||
)
|
16
components/mch2022-bsp/esp_efuse_custom_table.csv
Normal file
16
components/mch2022-bsp/esp_efuse_custom_table.csv
Normal file
|
@ -0,0 +1,16 @@
|
|||
# After editing this file, run the command manually "make efuse_custom_table" or "idf.py efuse_custom_table"
|
||||
|
||||
# WR_DIS_EFUSE_RD_DISABLE, EFUSE_BLK0, 0, 1, Write protection for RD_DIS, ADC_VREF
|
||||
WR_DIS_WR_DIS, EFUSE_BLK0, 1, 1, Write protection for WR_DIS
|
||||
# WR_DIS_FLASH_CRYPT_CNT, EFUSE_BLK0, 2, 1, Write protection for FLASH_CRYPT_CNT, UART_DOWNLOAD_DIS
|
||||
WR_DIS_MAC_AND_CHIP_INFO, EFUSE_BLK0, 3, 1, Write protection for MAC, MAC_CRC, CIP_VER_REV1, CHIP_VERSION, CHIP_PACKAGE
|
||||
WR_DIS_XPD, EFUSE_BLK0, 5, 1, Write protection for XPD_SDIO_FORCE, XPD_SDIO_REG, XPD_SDIO_TIEH
|
||||
WR_DIS_SPI_PAD, EFUSE_BLK0, 6, 1, Write protection for CHIP_VER_REV2, SPI_PAD_CONFIG
|
||||
# WR_DIS_BLK1, EFUSE_BLK0, 7, 1, Write protection for WR_DIS_BLK1
|
||||
# WR_DIS_BLK2, EFUSE_BLK0, 8, 1, Write protection for WR_DIS_BLK2
|
||||
# WR_DIS_BLK3, EFUSE_BLK0, 9, 1, Write protection for WR_DIS_BLK3, MAC_VERSION
|
||||
WR_DIS_SCHEME_KEY_CRYPT, EFUSE_BLK0, 10, 1, Write protection for CODING_SCHEME, KEY_STATUS, FLASH_CRYPT_CONFIG, BLK3_PART_RESERVE
|
||||
WR_DIS_ABS_DONE_0, EFUSE_BLK0, 12, 1, Write protection for ABS_DONE_0
|
||||
WR_DIS_ABS_DONE_1, EFUSE_BLK0, 13, 1, Write protection for ABS_DONE_1
|
||||
WR_DIS_JTAG_DISABLE, EFUSE_BLK0, 14, 1, Write protection for JTAG_DISABLE
|
||||
WR_DIS_CONSOLE_DEBUG_AND_DISABLE_DL_CRYPT, EFUSE_BLK0, 15, 1, Write protection for CONSOLE_DEBUG_DISABLE, DISABLE_DL
|
Can't render this file because it contains an unexpected character in line 1 and column 53.
|
|
@ -4,28 +4,31 @@
|
|||
#include <driver/gpio.h>
|
||||
#include "managed_i2c.h"
|
||||
#include "sdcard.h"
|
||||
#include "rp2040.h"
|
||||
|
||||
static const char *TAG = "hardware";
|
||||
|
||||
static PCA9555 dev_pca9555 = {0};
|
||||
static BNO055 dev_bno055 = {0};
|
||||
static BNO055 dev_bno055 = {0};
|
||||
static ILI9341 dev_ili9341 = {0};
|
||||
static ICE40 dev_ice40 = {0};
|
||||
static ICE40 dev_ice40 = {0};
|
||||
static RP2040 dev_rp2040 = {0};
|
||||
|
||||
// Wrapper functions for linking the ICE40 component to the PCA9555 component
|
||||
esp_err_t ice40_get_done_wrapper(bool* done) { return pca9555_get_gpio_value(&dev_pca9555, PCA9555_PIN_FPGA_CDONE, done); }
|
||||
esp_err_t ice40_set_reset_wrapper(bool reset) { return pca9555_set_gpio_value(&dev_pca9555, PCA9555_PIN_FPGA_RESET, reset); }
|
||||
esp_err_t ice40_get_done_wrapper(bool* done) {
|
||||
return pca9555_get_gpio_value(&dev_pca9555, PCA9555_PIN_FPGA_CDONE, done);
|
||||
}
|
||||
|
||||
esp_err_t hardware_init() {
|
||||
esp_err_t ice40_set_reset_wrapper(bool reset) {
|
||||
return pca9555_set_gpio_value(&dev_pca9555, PCA9555_PIN_FPGA_RESET, reset);
|
||||
}
|
||||
|
||||
void ili9341_set_lcd_mode(bool mode) {
|
||||
rp2040_set_lcd_mode(&dev_rp2040, (lcd_mode_t) mode);
|
||||
}
|
||||
|
||||
static esp_err_t _bus_init() {
|
||||
esp_err_t res;
|
||||
|
||||
// Interrupts
|
||||
res = gpio_install_isr_service(0);
|
||||
if (res != ESP_OK) {
|
||||
ESP_LOGE(TAG, "Initializing ISR service failed");
|
||||
return res;
|
||||
}
|
||||
|
||||
// System I2C bus
|
||||
res = i2c_init(I2C_BUS_SYS, GPIO_I2C_SYS_SDA, GPIO_I2C_SYS_SCL, I2C_SPEED_SYS, false, false);
|
||||
if (res != ESP_OK) {
|
||||
|
@ -54,6 +57,36 @@ esp_err_t hardware_init() {
|
|||
return res;
|
||||
}
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
// Board init
|
||||
|
||||
esp_err_t board_init() {
|
||||
esp_err_t res;
|
||||
|
||||
// Interrupts
|
||||
res = gpio_install_isr_service(0);
|
||||
if (res != ESP_OK) {
|
||||
ESP_LOGE(TAG, "Initializing ISR service failed");
|
||||
return res;
|
||||
}
|
||||
|
||||
// Communication busses
|
||||
res = _bus_init();
|
||||
if (res != ESP_OK) return res;
|
||||
|
||||
// RP2040 co-processor
|
||||
dev_rp2040.i2c_bus = I2C_BUS_SYS;
|
||||
dev_rp2040.i2c_address = RP2040_ADDR;
|
||||
dev_rp2040.pin_interrupt = GPIO_INT_RP2040;
|
||||
|
||||
res = rp2040_init(&dev_rp2040);
|
||||
if (res != ESP_OK) {
|
||||
ESP_LOGE(TAG, "Initializing RP2040 failed");
|
||||
return res;
|
||||
}
|
||||
|
||||
// PCA9555 IO expander on system I2C bus
|
||||
res = pca9555_init(&dev_pca9555, I2C_BUS_SYS, PCA9555_ADDR, GPIO_INT_PCA9555);
|
||||
if (res != ESP_OK) {
|
||||
|
@ -84,7 +117,7 @@ esp_err_t hardware_init() {
|
|||
pca9555_set_gpio_polarity(&dev_pca9555, PCA9555_PIN_BTN_JOY_RIGHT, true);
|
||||
pca9555_set_gpio_polarity(&dev_pca9555, PCA9555_PIN_BTN_BACK, true);
|
||||
pca9555_set_gpio_polarity(&dev_pca9555, PCA9555_PIN_BTN_ACCEPT, true);
|
||||
dev_pca9555.pin_state = 0; // Reset all pin states so that the interrupt function doesn't trigger all the handlers because we inverted the polarity
|
||||
dev_pca9555.pin_state = 0;
|
||||
|
||||
// FPGA
|
||||
dev_ice40.spi_bus = SPI_BUS;
|
||||
|
@ -112,7 +145,7 @@ esp_err_t hardware_init() {
|
|||
dev_ili9341.color_mode = true; // Blue and red channels are swapped
|
||||
dev_ili9341.spi_speed = 60000000; // 60MHz
|
||||
dev_ili9341.spi_max_transfer_size = SPI_MAX_TRANSFER_SIZE;
|
||||
dev_ili9341.callback = NULL; // Callback for changing LCD mode between ESP32 and FPGA
|
||||
dev_ili9341.callback = ili9341_set_lcd_mode; // Callback for changing LCD mode between ESP32 and FPGA
|
||||
|
||||
res = ili9341_init(&dev_ili9341);
|
||||
if (res != ESP_OK) {
|
||||
|
@ -127,7 +160,6 @@ esp_err_t hardware_init() {
|
|||
ESP_LOGE(TAG, "Initializing BNO055 failed");
|
||||
return res;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
@ -146,3 +178,7 @@ ILI9341* get_ili9341() {
|
|||
ICE40* get_ice40() {
|
||||
return &dev_ice40;
|
||||
}
|
||||
|
||||
RP2040* get_rp2040() {
|
||||
return &dev_rp2040;
|
||||
}
|
|
@ -7,15 +7,10 @@
|
|||
#include "bno055.h"
|
||||
#include "ili9341.h"
|
||||
#include "ice40.h"
|
||||
|
||||
esp_err_t hardware_init();
|
||||
PCA9555* get_pca9555();
|
||||
BNO055* get_bno055();
|
||||
ILI9341* get_ili9341();
|
||||
ICE40* get_ice40();
|
||||
#include "rp2040.h"
|
||||
|
||||
// Interrupts
|
||||
#define GPIO_INT_STM32 0
|
||||
#define GPIO_INT_RP2040 0
|
||||
#define GPIO_INT_PCA9555 34
|
||||
#define GPIO_INT_BNO055 36
|
||||
#define GPIO_INT_FPGA 39
|
||||
|
@ -38,25 +33,28 @@ ICE40* get_ice40();
|
|||
#define I2C_SPEED_SYS 20000 // 20 kHz
|
||||
|
||||
// PCA9555 IO expander
|
||||
#define PCA9555_ADDR 0x26
|
||||
#define PCA9555_PIN_STM32_RESET 0
|
||||
#define PCA9555_PIN_STM32_BOOT0 1
|
||||
#define PCA9555_PIN_FPGA_RESET 2
|
||||
#define PCA9555_PIN_FPGA_CDONE 3
|
||||
#define PCA9555_PIN_BTN_START 5
|
||||
#define PCA9555_PIN_BTN_SELECT 6
|
||||
#define PCA9555_PIN_BTN_MENU 7
|
||||
#define PCA9555_PIN_BTN_HOME 8
|
||||
#define PCA9555_PIN_BTN_JOY_LEFT 9
|
||||
#define PCA9555_PIN_BTN_JOY_PRESS 10
|
||||
#define PCA9555_PIN_BTN_JOY_DOWN 11
|
||||
#define PCA9555_PIN_BTN_JOY_UP 12
|
||||
#define PCA9555_PIN_BTN_JOY_RIGHT 13
|
||||
#define PCA9555_PIN_BTN_BACK 14
|
||||
#define PCA9555_PIN_BTN_ACCEPT 15
|
||||
#define PCA9555_ADDR 0x26
|
||||
#define PCA9555_PIN_RP2040_RESET 0
|
||||
#define PCA9555_PIN_RP2040_BOOTSEL 1
|
||||
#define PCA9555_PIN_FPGA_RESET 2
|
||||
#define PCA9555_PIN_FPGA_CDONE 3
|
||||
#define PCA9555_PIN_BTN_START 5
|
||||
#define PCA9555_PIN_BTN_SELECT 6
|
||||
#define PCA9555_PIN_BTN_MENU 7
|
||||
#define PCA9555_PIN_BTN_HOME 8
|
||||
#define PCA9555_PIN_BTN_JOY_LEFT 9
|
||||
#define PCA9555_PIN_BTN_JOY_PRESS 10
|
||||
#define PCA9555_PIN_BTN_JOY_DOWN 11
|
||||
#define PCA9555_PIN_BTN_JOY_UP 12
|
||||
#define PCA9555_PIN_BTN_JOY_RIGHT 13
|
||||
#define PCA9555_PIN_BTN_BACK 14
|
||||
#define PCA9555_PIN_BTN_ACCEPT 15
|
||||
|
||||
// RP2040 co-processor
|
||||
#define RP2040_ADDR 0x17
|
||||
|
||||
// BNO055 sensor
|
||||
#define BNO055_ADDR 0x28
|
||||
#define BNO055_ADDR 0x28
|
||||
|
||||
// User I2C bus
|
||||
#define GPIO_I2C_EXT_SCL 25
|
||||
|
@ -68,10 +66,18 @@ ICE40* get_ice40();
|
|||
#define GPIO_SPI_CLK 18
|
||||
#define GPIO_SPI_MOSI 23
|
||||
#define GPIO_SPI_MISO 35
|
||||
#define GPIO_SPI_CS_STM32 19
|
||||
#define GPIO_SPI_CS_RP2040 19
|
||||
#define GPIO_SPI_CS_FPGA 27
|
||||
#define GPIO_SPI_CS_LCD 32
|
||||
#define GPIO_SPI_DC_LCD 33
|
||||
#define SPI_BUS VSPI_HOST
|
||||
#define SPI_MAX_TRANSFER_SIZE 4094
|
||||
#define SPI_DMA_CHANNEL 2
|
||||
|
||||
esp_err_t board_init();
|
||||
|
||||
PCA9555* get_pca9555();
|
||||
BNO055* get_bno055();
|
||||
ILI9341* get_ili9341();
|
||||
ICE40* get_ice40();
|
||||
RP2040* get_rp2040();
|
127
components/mch2022-bsp/rp2040.c
Normal file
127
components/mch2022-bsp/rp2040.c
Normal file
|
@ -0,0 +1,127 @@
|
|||
/**
|
||||
* Copyright (c) 2022 Nicolai Electronics
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
|
||||
#include <sdkconfig.h>
|
||||
#include <driver/gpio.h>
|
||||
#include "rp2040.h"
|
||||
#include "managed_i2c.h"
|
||||
|
||||
static const char *TAG = "RP2040";
|
||||
|
||||
esp_err_t rp2040_init(RP2040* device) {
|
||||
esp_err_t res;
|
||||
|
||||
uint8_t firmware_version;
|
||||
res = rp2040_get_firmware_version(device, &firmware_version);
|
||||
if (res != ESP_OK) return res;
|
||||
|
||||
if (firmware_version != 1) {
|
||||
ESP_LOGE(TAG, "Unsupported RP2040 firmware version (%u) found", firmware_version);
|
||||
return ESP_ERR_INVALID_VERSION;
|
||||
}
|
||||
|
||||
res = i2c_read_reg(device->i2c_bus, device->i2c_address, RP2040_REG_GPIO_DIR, &device->_gpio_direction, 1);
|
||||
if (res != ESP_OK) return res;
|
||||
|
||||
res = i2c_read_reg(device->i2c_bus, device->i2c_address, RP2040_REG_GPIO_OUT, &device->_gpio_value, 1);
|
||||
if (res != ESP_OK) return res;
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t rp2040_get_firmware_version(RP2040* device, uint8_t* version) {
|
||||
return i2c_read_reg(device->i2c_bus, device->i2c_address, RP2040_REG_FW_VER, version, 1);
|
||||
}
|
||||
|
||||
esp_err_t rp2040_get_gpio_dir(RP2040* device, uint8_t gpio, bool* direction) {
|
||||
esp_err_t res = i2c_read_reg(device->i2c_bus, device->i2c_address, RP2040_REG_GPIO_DIR, &device->_gpio_direction, 1);
|
||||
if (res != ESP_OK) return res;
|
||||
*direction = (device->_gpio_direction >> gpio) & 0x01;
|
||||
return ESP_OK;
|
||||
}
|
||||
esp_err_t rp2040_set_gpio_dir(RP2040* device, uint8_t gpio, bool direction) {
|
||||
if (direction) {
|
||||
device->_gpio_direction |= 1UL << gpio;
|
||||
} else {
|
||||
device->_gpio_direction &= ~(1UL << gpio);
|
||||
}
|
||||
return i2c_write_reg_n(device->i2c_bus, device->i2c_address, RP2040_REG_GPIO_DIR, &device->_gpio_direction, 1);
|
||||
}
|
||||
|
||||
esp_err_t rp2040_get_gpio_value(RP2040* device, uint8_t gpio, bool* value) {
|
||||
uint8_t reg_value;
|
||||
esp_err_t res = i2c_read_reg(device->i2c_bus, device->i2c_address, RP2040_REG_GPIO_IN, ®_value, 1);
|
||||
if (res != ESP_OK) return res;
|
||||
*value = (reg_value >> gpio) & 0x01;
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t rp2040_set_gpio_value(RP2040* device, uint8_t gpio, bool value) {
|
||||
if (value) {
|
||||
device->_gpio_value |= 1UL << gpio;
|
||||
} else {
|
||||
device->_gpio_value &= ~(1UL << gpio);
|
||||
}
|
||||
return i2c_write_reg_n(device->i2c_bus, device->i2c_address, RP2040_REG_GPIO_OUT, &device->_gpio_value, 1);
|
||||
}
|
||||
|
||||
esp_err_t rp2040_get_lcd_mode(RP2040* device, lcd_mode_t* mode) {
|
||||
return i2c_read_reg(device->i2c_bus, device->i2c_address, RP2040_REG_LCD_MODE, (uint8_t*) mode, 1);
|
||||
}
|
||||
|
||||
esp_err_t rp2040_set_lcd_mode(RP2040* device, lcd_mode_t mode) {
|
||||
return i2c_write_reg_n(device->i2c_bus, device->i2c_address, RP2040_REG_LCD_MODE, (uint8_t*) &mode, 1);
|
||||
}
|
||||
|
||||
esp_err_t rp2040_get_lcd_backlight(RP2040* device, uint8_t* brightness) {
|
||||
return i2c_read_reg(device->i2c_bus, device->i2c_address, RP2040_REG_LCD_BACKLIGHT, brightness, 1);
|
||||
}
|
||||
|
||||
esp_err_t rp2040_set_lcd_backlight(RP2040* device, uint8_t brightness) {
|
||||
return i2c_write_reg_n(device->i2c_bus, device->i2c_address, RP2040_REG_LCD_BACKLIGHT, &brightness, 1);
|
||||
}
|
||||
|
||||
esp_err_t rp2040_get_led_mode(RP2040* device, bool* enabled, bool* automatic_flush) {
|
||||
uint8_t value;
|
||||
esp_err_t res = i2c_read_reg(device->i2c_bus, device->i2c_address, RP2040_REG_LED_MODE, &value, 1);
|
||||
if (res != ESP_OK) return res;
|
||||
*enabled = (value >> 0) & 0x01;
|
||||
*automatic_flush = (value >> 1) & 0x01;
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t rp2040_set_led_mode(RP2040* device, bool enabled, bool automatic_flush) {
|
||||
uint8_t value = enabled | (automatic_flush << 1);
|
||||
return i2c_write_reg_n(device->i2c_bus, device->i2c_address, RP2040_REG_LED_MODE, &value, 1);
|
||||
}
|
||||
|
||||
esp_err_t rp2040_get_led_value(RP2040* device, uint8_t led, uint8_t* red, uint8_t* green, uint8_t* blue) {
|
||||
if (led > 5) return ESP_ERR_NOT_FOUND;
|
||||
uint8_t value[3];
|
||||
esp_err_t res = i2c_read_reg(device->i2c_bus, device->i2c_address, RP2040_REG_LED_R0 + (led * 3), value, 3);
|
||||
if (res != ESP_OK) return res;
|
||||
*red = value[0];
|
||||
*green = value[1];
|
||||
*blue = value[2];
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t rp2040_set_led_value(RP2040* device, uint8_t led, uint8_t red, uint8_t green, uint8_t blue) {
|
||||
if (led > 5) return ESP_ERR_NOT_FOUND;
|
||||
uint8_t value[3];
|
||||
value[0] = red;
|
||||
value[1] = green;
|
||||
value[2] = blue;
|
||||
return i2c_write_reg_n(device->i2c_bus, device->i2c_address, RP2040_REG_LED_R0 + (led * 3), value, 3);
|
||||
}
|
||||
|
||||
esp_err_t rp2040_get_led_values(RP2040* device, uint8_t* buffer) {
|
||||
return i2c_read_reg(device->i2c_bus, device->i2c_address, RP2040_REG_LED_R0, buffer, 15);
|
||||
}
|
||||
|
||||
esp_err_t rp2040_set_led_values(RP2040* device, uint8_t* buffer) {
|
||||
return i2c_write_reg_n(device->i2c_bus, device->i2c_address, RP2040_REG_LED_R0, buffer, 15);
|
||||
}
|
77
components/mch2022-bsp/rp2040.h
Normal file
77
components/mch2022-bsp/rp2040.h
Normal file
|
@ -0,0 +1,77 @@
|
|||
#pragma once
|
||||
|
||||
#include <esp_err.h>
|
||||
#include <esp_log.h>
|
||||
#include <stdint.h>
|
||||
#include <freertos/FreeRTOS.h>
|
||||
#include <freertos/semphr.h>
|
||||
#include <freertos/task.h>
|
||||
|
||||
enum {
|
||||
RP2040_REG_FW_VER = 0,
|
||||
RP2040_REG_GPIO_DIR,
|
||||
RP2040_REG_GPIO_IN,
|
||||
RP2040_REG_GPIO_OUT,
|
||||
RP2040_REG_LCD_MODE,
|
||||
RP2040_REG_LCD_BACKLIGHT,
|
||||
RP2040_REG_LED_MODE,
|
||||
RP2040_REG_LED_R0,
|
||||
RP2040_REG_LED_G0,
|
||||
RP2040_REG_LED_B0,
|
||||
RP2040_REG_LED_R1,
|
||||
RP2040_REG_LED_G1,
|
||||
RP2040_REG_LED_B1,
|
||||
RP2040_REG_LED_R2,
|
||||
RP2040_REG_LED_G2,
|
||||
RP2040_REG_LED_B2,
|
||||
RP2040_REG_LED_R3,
|
||||
RP2040_REG_LED_G3,
|
||||
RP2040_REG_LED_B3,
|
||||
RP2040_REG_LED_R4,
|
||||
RP2040_REG_LED_G4,
|
||||
RP2040_REG_LED_B4,
|
||||
};
|
||||
|
||||
typedef enum {
|
||||
LCD_MODE_SPI = 0,
|
||||
LCD_MODE_PARALLEL = 1
|
||||
} lcd_mode_t;
|
||||
|
||||
typedef void (*rp2040_intr_t)();
|
||||
|
||||
typedef struct {
|
||||
int i2c_bus;
|
||||
int i2c_address;
|
||||
int pin_interrupt;
|
||||
rp2040_intr_t _intr_handler;
|
||||
TaskHandle_t _intr_task_handle;
|
||||
xSemaphoreHandle _intr_trigger;
|
||||
xSemaphoreHandle _mux;
|
||||
uint8_t _gpio_direction;
|
||||
uint8_t _gpio_value;
|
||||
} RP2040;
|
||||
|
||||
esp_err_t rp2040_init(RP2040* device);
|
||||
|
||||
esp_err_t rp2040_get_firmware_version(RP2040* device, uint8_t* version);
|
||||
|
||||
esp_err_t rp2040_get_gpio_dir(RP2040* device, uint8_t gpio, bool* direction);
|
||||
esp_err_t rp2040_set_gpio_dir(RP2040* device, uint8_t gpio, bool direction);
|
||||
|
||||
esp_err_t rp2040_get_gpio_value(RP2040* device, uint8_t gpio, bool* value);
|
||||
esp_err_t rp2040_set_gpio_value(RP2040* device, uint8_t gpio, bool value);
|
||||
|
||||
esp_err_t rp2040_get_lcd_mode(RP2040* device, lcd_mode_t* mode);
|
||||
esp_err_t rp2040_set_lcd_mode(RP2040* device, lcd_mode_t mode);
|
||||
|
||||
esp_err_t rp2040_get_lcd_backlight(RP2040* device, uint8_t* brightness);
|
||||
esp_err_t rp2040_set_lcd_backlight(RP2040* device, uint8_t brightness);
|
||||
|
||||
esp_err_t rp2040_get_led_mode(RP2040* device, bool* enabled, bool* automatic_flush);
|
||||
esp_err_t rp2040_set_led_mode(RP2040* device, bool enabled, bool automatic_flush);
|
||||
|
||||
esp_err_t rp2040_get_led_value(RP2040* device, uint8_t led, uint8_t* red, uint8_t* green, uint8_t* blue);
|
||||
esp_err_t rp2040_set_led_value(RP2040* device, uint8_t led, uint8_t red, uint8_t green, uint8_t blue);
|
||||
|
||||
esp_err_t rp2040_get_led_values(RP2040* device, uint8_t* buffer); // Expects a buffer that can fit 15 bytes (R, G, B * 5 LEDs)
|
||||
esp_err_t rp2040_set_led_values(RP2040* device, uint8_t* buffer); // Expects a buffer that can contains 15 bytes (R, G, B * 5 LEDs)
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue