Skip to content

Commit 5fbad19

Browse files
hfmansonrenzenicolai
authored andcommitted
IDF v5.5.1 and Tanmatsu support (#55)
1 parent c849da3 commit 5fbad19

42 files changed

Lines changed: 1043 additions & 733 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

components/buses/CMakeLists.txt

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1+
#get_cmake_property(_vars VARIABLES)
2+
#foreach(v ${_vars})
3+
# message(STATUS "${v} = [${${v}}]")
4+
#endforeach()
5+
16
idf_component_register(
27
SRCS "buses.c"
3-
INCLUDE_DIRS include
4-
)
8+
INCLUDE_DIRS include ${PROJECT_DIR}
9+
REQUIRES
10+
micropython
11+
driver
12+
freertos)

components/buses/buses.c

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,11 @@
2222
#define ACK_VAL 0x0 // I2C ack value
2323
#define NACK_VAL 0x1 // I2C nack value
2424

25-
static xSemaphoreHandle i2c0_mux = NULL;
26-
static xSemaphoreHandle i2c1_mux = NULL;
25+
26+
static SemaphoreHandle_t i2c0_mux = NULL;
27+
static SemaphoreHandle_t i2c1_mux = NULL;
28+
29+
static const char* TAG = "buses";
2730

2831
esp_err_t start_buses() {
2932
// This function initializes the VSPI, HSPI and I2C buses of the ESP32
@@ -129,9 +132,9 @@ esp_err_t driver_i2c_read_bytes(int bus, uint8_t addr, uint8_t *value, size_t va
129132
res = i2c_master_stop(cmd);
130133
if (res != ESP_OK) { i2c_cmd_link_delete(cmd); return res; }
131134

132-
xSemaphoreHandle mux = (bus == I2C_NUM_1) ? i2c1_mux : i2c0_mux;
135+
SemaphoreHandle_t mux = (bus == I2C_NUM_1) ? i2c1_mux : i2c0_mux;
133136
if (xSemaphoreTake(mux, portMAX_DELAY) != pdTRUE) return ESP_ERR_TIMEOUT; // Wait for I2C bus to become available
134-
res = i2c_master_cmd_begin(bus, cmd, 1000 / portTICK_RATE_MS);
137+
res = i2c_master_cmd_begin(bus, cmd, 1000 / portTICK_PERIOD_MS);
135138
i2c_cmd_link_delete(cmd);
136139
xSemaphoreGive(mux);
137140
return res;
@@ -158,9 +161,9 @@ esp_err_t driver_i2c_read_reg(int bus, uint8_t addr, uint8_t reg, uint8_t *value
158161
res = i2c_master_stop(cmd);
159162
if (res != ESP_OK) { i2c_cmd_link_delete(cmd); return res; }
160163

161-
xSemaphoreHandle mux = (bus == I2C_NUM_1) ? i2c1_mux : i2c0_mux;
164+
SemaphoreHandle_t mux = (bus == I2C_NUM_1) ? i2c1_mux : i2c0_mux;
162165
if (xSemaphoreTake(mux, portMAX_DELAY) != pdTRUE) return ESP_ERR_TIMEOUT; // Wait for I2C bus to become available
163-
res = i2c_master_cmd_begin(bus, cmd, 1000 / portTICK_RATE_MS);
166+
res = i2c_master_cmd_begin(bus, cmd, 1000 / portTICK_PERIOD_MS);
164167
i2c_cmd_link_delete(cmd);
165168
xSemaphoreGive(mux);
166169
return res;
@@ -179,9 +182,9 @@ esp_err_t driver_i2c_read_event(int bus, uint8_t addr, uint8_t *buf) {
179182
res = i2c_master_stop(cmd);
180183
if (res != ESP_OK) { i2c_cmd_link_delete(cmd); return res; }
181184

182-
xSemaphoreHandle mux = (bus == I2C_NUM_1) ? i2c1_mux : i2c0_mux;
185+
SemaphoreHandle_t mux = (bus == I2C_NUM_1) ? i2c1_mux : i2c0_mux;
183186
if (xSemaphoreTake(mux, portMAX_DELAY) != pdTRUE) return ESP_ERR_TIMEOUT; // Wait for I2C bus to become available
184-
res = i2c_master_cmd_begin(bus, cmd, 1000 / portTICK_RATE_MS);
187+
res = i2c_master_cmd_begin(bus, cmd, 1000 / portTICK_PERIOD_MS);
185188
i2c_cmd_link_delete(cmd);
186189
xSemaphoreGive(mux);
187190
return res;
@@ -198,9 +201,9 @@ esp_err_t driver_i2c_write_byte(int bus, uint8_t addr, uint8_t value) {
198201
res = i2c_master_stop(cmd);
199202
if (res != ESP_OK) { i2c_cmd_link_delete(cmd); return res; }
200203

201-
xSemaphoreHandle mux = (bus == I2C_NUM_1) ? i2c1_mux : i2c0_mux;
204+
SemaphoreHandle_t mux = (bus == I2C_NUM_1) ? i2c1_mux : i2c0_mux;
202205
if (xSemaphoreTake(mux, portMAX_DELAY) != pdTRUE) return ESP_ERR_TIMEOUT; // Wait for I2C bus to become available
203-
res = i2c_master_cmd_begin(bus, cmd, 1000 / portTICK_RATE_MS);
206+
res = i2c_master_cmd_begin(bus, cmd, 1000 / portTICK_PERIOD_MS);
204207
i2c_cmd_link_delete(cmd);
205208
xSemaphoreGive(mux);
206209
return res;
@@ -219,9 +222,9 @@ esp_err_t driver_i2c_write_reg(int bus, uint8_t addr, uint8_t reg, uint8_t value
219222
res = i2c_master_stop(cmd);
220223
if (res != ESP_OK) { i2c_cmd_link_delete(cmd); return res; }
221224

222-
xSemaphoreHandle mux = (bus == I2C_NUM_1) ? i2c1_mux : i2c0_mux;
225+
SemaphoreHandle_t mux = (bus == I2C_NUM_1) ? i2c1_mux : i2c0_mux;
223226
if (xSemaphoreTake(mux, portMAX_DELAY) != pdTRUE) return ESP_ERR_TIMEOUT; // Wait for I2C bus to become available
224-
res = i2c_master_cmd_begin(bus, cmd, 1000 / portTICK_RATE_MS);
227+
res = i2c_master_cmd_begin(bus, cmd, 1000 / portTICK_PERIOD_MS);
225228
i2c_cmd_link_delete(cmd);
226229
xSemaphoreGive(mux);
227230
return res;
@@ -242,9 +245,9 @@ esp_err_t driver_i2c_write_reg_n(int bus, uint8_t addr, uint8_t reg, uint8_t *va
242245
res = i2c_master_stop(cmd);
243246
if (res != ESP_OK) { i2c_cmd_link_delete(cmd); return res; }
244247

245-
xSemaphoreHandle mux = (bus == I2C_NUM_1) ? i2c1_mux : i2c0_mux;
248+
SemaphoreHandle_t mux = (bus == I2C_NUM_1) ? i2c1_mux : i2c0_mux;
246249
if (xSemaphoreTake(mux, portMAX_DELAY) != pdTRUE) return ESP_ERR_TIMEOUT; // Wait for I2C bus to become available
247-
res = i2c_master_cmd_begin(bus, cmd, 1000 / portTICK_RATE_MS);
250+
res = i2c_master_cmd_begin(bus, cmd, 1000 / portTICK_PERIOD_MS);
248251
i2c_cmd_link_delete(cmd);
249252
xSemaphoreGive(mux);
250253
return res;
@@ -263,9 +266,9 @@ esp_err_t driver_i2c_write_buffer(int bus, uint8_t addr, const uint8_t* buffer,
263266
res = i2c_master_stop(cmd);
264267
if (res != ESP_OK) { i2c_cmd_link_delete(cmd); return res; }
265268

266-
xSemaphoreHandle mux = (bus == I2C_NUM_1) ? i2c1_mux : i2c0_mux;
269+
SemaphoreHandle_t mux = (bus == I2C_NUM_1) ? i2c1_mux : i2c0_mux;
267270
if (xSemaphoreTake(mux, portMAX_DELAY) != pdTRUE) return ESP_ERR_TIMEOUT; // Wait for I2C bus to become available
268-
res = i2c_master_cmd_begin(bus, cmd, 1000 / portTICK_RATE_MS);
271+
res = i2c_master_cmd_begin(bus, cmd, 1000 / portTICK_PERIOD_MS);
269272
i2c_cmd_link_delete(cmd);
270273
xSemaphoreGive(mux);
271274
return res;
@@ -286,9 +289,9 @@ esp_err_t driver_i2c_write_buffer_reg(int bus, uint8_t addr, uint8_t reg, const
286289
res = i2c_master_stop(cmd);
287290
if (res != ESP_OK) { i2c_cmd_link_delete(cmd); return res; }
288291

289-
xSemaphoreHandle mux = (bus == I2C_NUM_1) ? i2c1_mux : i2c0_mux;
292+
SemaphoreHandle_t mux = (bus == I2C_NUM_1) ? i2c1_mux : i2c0_mux;
290293
if (xSemaphoreTake(mux, portMAX_DELAY) != pdTRUE) return ESP_ERR_TIMEOUT; // Wait for I2C bus to become available
291-
res = i2c_master_cmd_begin(bus, cmd, 1000 / portTICK_RATE_MS);
294+
res = i2c_master_cmd_begin(bus, cmd, 1000 / portTICK_PERIOD_MS);
292295
i2c_cmd_link_delete(cmd);
293296
xSemaphoreGive(mux);
294297
return res;
@@ -313,9 +316,9 @@ esp_err_t driver_i2c_write_reg32(int bus, uint8_t addr, uint8_t reg, uint32_t va
313316
res = i2c_master_stop(cmd);
314317
if (res != ESP_OK) { i2c_cmd_link_delete(cmd); return res; }
315318

316-
xSemaphoreHandle mux = (bus == I2C_NUM_1) ? i2c1_mux : i2c0_mux;
319+
SemaphoreHandle_t mux = (bus == I2C_NUM_1) ? i2c1_mux : i2c0_mux;
317320
if (xSemaphoreTake(mux, portMAX_DELAY) != pdTRUE) return ESP_ERR_TIMEOUT; // Wait for I2C bus to become available
318-
res = i2c_master_cmd_begin(bus, cmd, 1000 / portTICK_RATE_MS);
321+
res = i2c_master_cmd_begin(bus, cmd, 1000 / portTICK_PERIOD_MS);
319322
i2c_cmd_link_delete(cmd);
320323
xSemaphoreGive(mux);
321324
return res;

components/buses/include/buses.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <esp_err.h>
55

66
extern esp_err_t start_buses();
7+
78
extern esp_err_t driver_i2c_read_bytes(int bus, uint8_t addr, uint8_t *value, size_t value_len);
89
extern esp_err_t driver_i2c_read_reg(int bus, uint8_t addr, uint8_t reg, uint8_t *value, size_t value_len);
910
extern esp_err_t driver_i2c_read_event(int bus, uint8_t addr, uint8_t *buf);

components/consts/CMakeLists.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Compute the MicroPython root relative to this component
2+
set(MP_ROOT ${PROJECT_DIR}/../..)
3+
4+
idf_component_register(
5+
SRCS "modconsts.c"
6+
PRIV_INCLUDE_DIRS
7+
${MP_ROOT} # micropython/
8+
${PROJECT_DIR} # micropython/ports/esp32
9+
${MICROPY_BOARD_DIR} # board headers (mpconfigboard.h)
10+
${CMAKE_CURRENT_LIST_DIR}/..
11+
${BUILD_DIR}
12+
REQUIRES
13+
micropython
14+
driver
15+
freertos)

components/consts/Kconfig

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
menu "Firmware & device configuration"
2+
config INFO_FIRMWARE_NAME
3+
string "Code-name of the firmware"
4+
default "Unknown"
5+
6+
config INFO_FIRMWARE_BUILD
7+
int "Build number of the firmware"
8+
default 0
9+
10+
config INFO_HARDWARE_NAME
11+
string "Name of the device"
12+
default "Generic device"
13+
help
14+
A semantic name for your badge
15+
16+
config MICROPY_FROZEN_MANIFEST
17+
string "Manifest to load modules from stored in the manifests folder"
18+
default "manifest.py"
19+
20+
config INFO_HARDWARE_WOEZEL_NAME
21+
string "Name of the badge on the app hatchery"
22+
default "generic"
23+
24+
config OTA_WEB_SERVER
25+
string "Hostname of server for OTA updates"
26+
default "badge.team"
27+
28+
config OTA_WEB_USE_HTTPS
29+
bool "Use HTTPS for OTA updates"
30+
default y
31+
32+
config OTA_WEB_PORT
33+
int "Port of server for OTA updates"
34+
default 443
35+
36+
config OTA_WEB_PATH
37+
string "Path on the server for OTA updates"
38+
default "/firmware/unknown.bin"
39+
40+
config OTA_WEB_VERSION_PATH
41+
string "Path on the server for OTA update version"
42+
default "/firmware/version/unknown.txt"
43+
44+
config WOEZEL_WEB_SERVER
45+
string "Hostname of server for app hatchery that contains user apps"
46+
default "badge.team"
47+
48+
config WIFI_SSID
49+
string "Default WiFi ssid"
50+
default "badge"
51+
52+
config WIFI_PASSWORD
53+
string "Default WiFi password, leave empty for unsecure network"
54+
default ""
55+
56+
choice
57+
prompt "Default display orientation"
58+
default DEFAULT_DISPLAY_ORIENTATION_LANDSCAPE
59+
config DEFAULT_DISPLAY_ORIENTATION_LANDSCAPE
60+
bool "Landscape (0 degrees)"
61+
config DEFAULT_DISPLAY_ORIENTATION_PORTRAIT
62+
bool "Portrait (90 degrees)"
63+
config DEFAULT_DISPLAY_ORIENTATION_REVERSE_LANDSCAPE
64+
bool "Reverse landscape (180 degrees)"
65+
config DEFAULT_DISPLAY_ORIENTATION_REVERSE_PORTRAIT
66+
bool "Reverse portrait (270 degrees)"
67+
endchoice
68+
69+
config FW_ENABLE_SHA2017_DISOBEY2019_PARTITION_TABLE_UPGRADE
70+
bool "Enable partition table upgrade function for SHA2017 and Disobey 2019 badges"
71+
default n
72+
73+
config FW_DISABLE_OTA_AND_FIRSTBOOT
74+
bool "Disable OTA update function and first boot ZIP unpacking"
75+
default n
76+
endmenu

components/consts/modconsts.c

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#include "sdkconfig.h"
2+
#include <time.h>
3+
#include <string.h>
4+
#include "py/builtin.h"
5+
#include "py/objlist.h"
6+
#include "py/objtuple.h"
7+
#include "py/objstr.h"
8+
#include "py/objint.h"
9+
#include "py/objtype.h"
10+
#include "py/stream.h"
11+
#include "py/smallint.h"
12+
#include "py/runtime.h"
13+
#include "shared/runtime/pyexec.h"
14+
15+
#define INT_TO_STR_EX(number) #number
16+
#define INT_TO_STR(number) INT_TO_STR_EX(number)
17+
18+
#ifdef CONFIG_OTA_WEB_USE_HTTPS
19+
#define OTA_PROTOCOL "https"
20+
#else
21+
#define OTA_PROTOCOL "http"
22+
#endif
23+
24+
#if defined(CONFIG_DEFAULT_DISPLAY_ORIENTATION_PORTRAIT)
25+
#define DEFAULT_ORIENTATION 90
26+
#elif defined(CONFIG_DEFAULT_DISPLAY_ORIENTATION_REVERSE_LANDSCAPE)
27+
#define DEFAULT_ORIENTATION 180
28+
#elif defined(CONFIG_DEFAULT_DISPLAY_ORIENTATION_REVERSE_PORTRAIT)
29+
#define DEFAULT_ORIENTATION 270
30+
#else
31+
#define DEFAULT_ORIENTATION 0
32+
#endif
33+
34+
static const MP_DEFINE_STR_OBJ( info_firmware_name_obj, CONFIG_INFO_FIRMWARE_NAME );
35+
static const MP_DEFINE_STR_OBJ( info_hardware_name_obj, CONFIG_INFO_HARDWARE_NAME );
36+
static const MP_DEFINE_STR_OBJ( info_hardware_folder_obj, CONFIG_MICROPY_FROZEN_MANIFEST );
37+
static const MP_DEFINE_STR_OBJ( ota_web_server_obj, CONFIG_OTA_WEB_SERVER );
38+
static const MP_DEFINE_STR_OBJ( ota_web_port_obj, INT_TO_STR(CONFIG_OTA_WEB_PORT) );
39+
static const MP_DEFINE_STR_OBJ( ota_web_protocol_obj, OTA_PROTOCOL );
40+
static const MP_DEFINE_STR_OBJ( ota_web_path_obj, CONFIG_OTA_WEB_PATH );
41+
static const MP_DEFINE_STR_OBJ( ota_web_version_path_obj, CONFIG_OTA_WEB_VERSION_PATH );
42+
static const MP_DEFINE_STR_OBJ( info_woezel_web_server_obj, CONFIG_WOEZEL_WEB_SERVER );
43+
static const MP_DEFINE_STR_OBJ( info_hardware_woezel_name_obj, CONFIG_INFO_HARDWARE_WOEZEL_NAME );
44+
static const MP_DEFINE_STR_OBJ( wifi_ssid_obj, CONFIG_WIFI_SSID );
45+
static const MP_DEFINE_STR_OBJ( wifi_pass_obj, CONFIG_WIFI_PASSWORD );
46+
47+
static const mp_rom_map_elem_t consts_module_globals_table[] = {
48+
{ MP_ROM_QSTR(MP_QSTR_INFO_FIRMWARE_NAME ), MP_ROM_PTR( &info_firmware_name_obj ) },
49+
{ MP_ROM_QSTR(MP_QSTR_INFO_FIRMWARE_BUILD ), MP_ROM_INT( CONFIG_INFO_FIRMWARE_BUILD ) },
50+
{ MP_ROM_QSTR(MP_QSTR_INFO_HARDWARE_NAME ), MP_ROM_PTR( &info_hardware_name_obj ) },
51+
{ MP_ROM_QSTR(MP_QSTR_INFO_HARDWARE_FOLDER ), MP_ROM_PTR( &info_hardware_folder_obj ) },
52+
{ MP_ROM_QSTR(MP_QSTR_WOEZEL_WEB_SERVER ), MP_ROM_PTR( &info_woezel_web_server_obj ) },
53+
{ MP_ROM_QSTR(MP_QSTR_INFO_HARDWARE_WOEZEL_NAME ), MP_ROM_PTR( &info_hardware_woezel_name_obj ) },
54+
{ MP_ROM_QSTR(MP_QSTR_OTA_WEB_SERVER ), MP_ROM_PTR( &ota_web_server_obj ) },
55+
{ MP_ROM_QSTR(MP_QSTR_OTA_WEB_PORT ), MP_ROM_PTR( &ota_web_port_obj ) },
56+
{ MP_ROM_QSTR(MP_QSTR_OTA_WEB_PROTOCOL ), MP_ROM_PTR( &ota_web_protocol_obj ) },
57+
{ MP_ROM_QSTR(MP_QSTR_OTA_WEB_PATH ), MP_ROM_PTR( &ota_web_path_obj ) },
58+
{ MP_ROM_QSTR(MP_QSTR_OTA_WEB_VERSION_PATH ), MP_ROM_PTR( &ota_web_version_path_obj ) },
59+
{ MP_ROM_QSTR(MP_QSTR_WIFI_SSID ), MP_ROM_PTR( &wifi_ssid_obj ) },
60+
{ MP_ROM_QSTR(MP_QSTR_WIFI_PASSWORD ), MP_ROM_PTR( &wifi_pass_obj ) },
61+
{ MP_ROM_QSTR(MP_QSTR_DEFAULT_ORIENTATION ), MP_ROM_INT( DEFAULT_ORIENTATION ) },
62+
};
63+
64+
static MP_DEFINE_CONST_DICT(consts_module_globals, consts_module_globals_table);
65+
66+
const mp_obj_module_t consts_module = {
67+
.base = { &mp_type_module },
68+
.globals = (mp_obj_dict_t*)&consts_module_globals,
69+
};
70+
MP_REGISTER_MODULE(MP_QSTR_consts, consts_module);
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
if(CONFIG_DRIVER_BADGE_BSP_ENABLE)
2+
set(srcs
3+
"driver_badge_bsp.c"
4+
)
5+
set(includes
6+
"include"
7+
)
8+
else()
9+
set(srcs "")
10+
set(includes
11+
""
12+
)
13+
endif()
14+
15+
idf_component_register(
16+
SRCS "${srcs}"
17+
INCLUDE_DIRS ${includes}
18+
REQUIRES micropython badge-bsp
19+
)
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
menu "Driver: Badge BSP display"
2+
config DRIVER_BADGE_BSP_ENABLE
3+
bool "Enable the Badge BSP display driver"
4+
default n
5+
6+
endmenu
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#include <sdkconfig.h>
2+
#include <stdbool.h>
3+
#include <stdint.h>
4+
#include <stdio.h>
5+
#include <string.h>
6+
7+
#include <esp_err.h>
8+
#include <esp_log.h>
9+
10+
#include "include/driver_badge_bsp.h"
11+
12+
#define TAG "badge_bsp"
13+
14+
static size_t h_res;
15+
static size_t v_res;
16+
static lcd_color_rgb_pixel_format_t color_fmt;
17+
static lcd_rgb_data_endian_t data_endian;
18+
19+
esp_err_t driver_badge_bsp_init(void)
20+
{
21+
esp_err_t err = bsp_display_get_parameters(&h_res, &v_res, &color_fmt, &data_endian);
22+
if (err == ESP_OK) {
23+
ESP_LOGI(TAG, "h_res: %d, v_res: %d, color_fmt: %d, data_endian: %d", h_res, v_res, color_fmt, data_endian);
24+
} else {
25+
ESP_LOGI(TAG, "error: %d", err);
26+
}
27+
return err;
28+
}
29+
30+
size_t driver_badge_bsp_get_width(void)
31+
{
32+
return h_res;
33+
}
34+
35+
size_t driver_badge_bsp_get_height(void)
36+
{
37+
return v_res;
38+
}
39+
40+
size_t driver_badge_bsp_get_size(void)
41+
{
42+
size_t size = h_res * v_res * 2;
43+
return size;
44+
}
45+
46+
esp_err_t driver_badge_bsp_set_backlight_brightness(uint8_t percentage)
47+
{
48+
return bsp_display_set_backlight_brightness(percentage);
49+
}
50+
51+
esp_err_t driver_badge_bsp_flush(const uint8_t *buffer, uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1) {
52+
return bsp_display_blit(x0, y0, x1 - x0 + 1, y1 - y0 + 1, buffer);
53+
}

0 commit comments

Comments
 (0)