Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,8 @@ sdkconfig
sdkconfig.old
partitions.csv
sdkconfig.defaults
esp-idf
esp-idf-tools
dependencies.lock
managed_components

3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
[submodule "firmware/components/micropython/micropython"]
path = components/micropython/micropython
url = https://github.com/micropython/micropython.git
[submodule "esp-idf"]
path = esp-idf
url = https://github.com/espressif/esp-idf.git
[submodule "firmware/python_modules/micropython-lib"]
path = python_modules/micropython-lib
url = https://github.com/micropython/micropython-lib
Expand Down
20 changes: 17 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,16 +1,30 @@
PORT ?= /dev/ttyACM0

IDF_PATH ?= $(shell cat .IDF_PATH 2>/dev/null || echo `pwd`/esp-idf)
IDF_TOOLS_PATH ?= $(shell cat .IDF_TOOLS_PATH 2>/dev/null || echo `pwd`/esp-idf-tools)
IDF_BRANCH ?= v5.5.1
IDF_EXPORT_QUIET ?= 1
IDF_GITHUB_ASSETS ?= dl.espressif.com/github_assets
MAKEFLAGS += --silent

BUILDDIR ?= build
IDF_PATH ?= $(shell pwd)/esp-idf
IDF_EXPORT_QUIET ?= 0
SHELL := /usr/bin/env bash

.PHONY: prepare clean build flash erase monitor menuconfig image qemu install prepare-mch2022 prepare-cz19 mch2022 clean-frozen

all: prepare build

prepare:
.PHONY: sdk
sdk:
if test -d "$(IDF_PATH)"; then echo -e "ESP-IDF target folder exists!\r\nPlease remove the folder or un-set the environment variable."; exit 1; fi
if test -d "$(IDF_TOOLS_PATH)"; then echo -e "ESP-IDF tools target folder exists!\r\nPlease remove the folder or un-set the environment variable."; exit 1; fi
git clone --recursive --branch "$(IDF_BRANCH)" https://github.com/espressif/esp-idf.git "$(IDF_PATH)" --depth=1 --shallow-submodules
cd "$(IDF_PATH)"; git submodule update --init --recursive
cd "$(IDF_PATH)"; bash install.sh all

prepare: sdk
git submodule update --init --recursive
cd esp-idf; bash install.sh; cd ..
cd components/micropython/micropython/mpy-cross; make
cp configs/default_defconfig sdkconfig
cp partition_tables/default.csv partitions.csv
Expand Down
12 changes: 10 additions & 2 deletions components/buses/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
#get_cmake_property(_vars VARIABLES)
#foreach(v ${_vars})
# message(STATUS "${v} = [${${v}}]")
#endforeach()

idf_component_register(
SRCS "buses.c"
INCLUDE_DIRS include
)
INCLUDE_DIRS include ${PROJECT_DIR}
REQUIRES
micropython
driver
freertos)
43 changes: 23 additions & 20 deletions components/buses/buses.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,11 @@
#define ACK_VAL 0x0 // I2C ack value
#define NACK_VAL 0x1 // I2C nack value

static xSemaphoreHandle i2c0_mux = NULL;
static xSemaphoreHandle i2c1_mux = NULL;

static SemaphoreHandle_t i2c0_mux = NULL;
static SemaphoreHandle_t i2c1_mux = NULL;

static const char* TAG = "buses";

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

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

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

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

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

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

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

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

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

xSemaphoreHandle mux = (bus == I2C_NUM_1) ? i2c1_mux : i2c0_mux;
SemaphoreHandle_t mux = (bus == I2C_NUM_1) ? i2c1_mux : i2c0_mux;
if (xSemaphoreTake(mux, portMAX_DELAY) != pdTRUE) return ESP_ERR_TIMEOUT; // Wait for I2C bus to become available
res = i2c_master_cmd_begin(bus, cmd, 1000 / portTICK_RATE_MS);
res = i2c_master_cmd_begin(bus, cmd, 1000 / portTICK_PERIOD_MS);
i2c_cmd_link_delete(cmd);
xSemaphoreGive(mux);
return res;
Expand Down
1 change: 1 addition & 0 deletions components/buses/include/buses.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <esp_err.h>

extern esp_err_t start_buses();

extern esp_err_t driver_i2c_read_bytes(int bus, uint8_t addr, uint8_t *value, size_t value_len);
extern esp_err_t driver_i2c_read_reg(int bus, uint8_t addr, uint8_t reg, uint8_t *value, size_t value_len);
extern esp_err_t driver_i2c_read_event(int bus, uint8_t addr, uint8_t *buf);
Expand Down
15 changes: 15 additions & 0 deletions components/consts/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Compute the MicroPython root relative to this component
set(MP_ROOT ${PROJECT_DIR}/../..)

idf_component_register(
SRCS "modconsts.c"
PRIV_INCLUDE_DIRS
${MP_ROOT} # micropython/
${PROJECT_DIR} # micropython/ports/esp32
${MICROPY_BOARD_DIR} # board headers (mpconfigboard.h)
${CMAKE_CURRENT_LIST_DIR}/..
${BUILD_DIR}
REQUIRES
micropython
driver
freertos)
76 changes: 76 additions & 0 deletions components/consts/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
menu "Firmware & device configuration"
config INFO_FIRMWARE_NAME
string "Code-name of the firmware"
default "Unknown"

config INFO_FIRMWARE_BUILD
int "Build number of the firmware"
default 0

config INFO_HARDWARE_NAME
string "Name of the device"
default "Generic device"
help
A semantic name for your badge

config MICROPY_FROZEN_MANIFEST
string "Manifest to load modules from stored in the manifests folder"
default "manifest.py"

config INFO_HARDWARE_WOEZEL_NAME
string "Name of the badge on the app hatchery"
default "generic"

config OTA_WEB_SERVER
string "Hostname of server for OTA updates"
default "badge.team"

config OTA_WEB_USE_HTTPS
bool "Use HTTPS for OTA updates"
default y

config OTA_WEB_PORT
int "Port of server for OTA updates"
default 443

config OTA_WEB_PATH
string "Path on the server for OTA updates"
default "/firmware/unknown.bin"

config OTA_WEB_VERSION_PATH
string "Path on the server for OTA update version"
default "/firmware/version/unknown.txt"

config WOEZEL_WEB_SERVER
string "Hostname of server for app hatchery that contains user apps"
default "badge.team"

config WIFI_SSID
string "Default WiFi ssid"
default "badge"

config WIFI_PASSWORD
string "Default WiFi password, leave empty for unsecure network"
default ""

choice
prompt "Default display orientation"
default DEFAULT_DISPLAY_ORIENTATION_LANDSCAPE
config DEFAULT_DISPLAY_ORIENTATION_LANDSCAPE
bool "Landscape (0 degrees)"
config DEFAULT_DISPLAY_ORIENTATION_PORTRAIT
bool "Portrait (90 degrees)"
config DEFAULT_DISPLAY_ORIENTATION_REVERSE_LANDSCAPE
bool "Reverse landscape (180 degrees)"
config DEFAULT_DISPLAY_ORIENTATION_REVERSE_PORTRAIT
bool "Reverse portrait (270 degrees)"
endchoice

config FW_ENABLE_SHA2017_DISOBEY2019_PARTITION_TABLE_UPGRADE
bool "Enable partition table upgrade function for SHA2017 and Disobey 2019 badges"
default n

config FW_DISABLE_OTA_AND_FIRSTBOOT
bool "Disable OTA update function and first boot ZIP unpacking"
default n
endmenu
70 changes: 70 additions & 0 deletions components/consts/modconsts.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#include "sdkconfig.h"
#include <time.h>
#include <string.h>
#include "py/builtin.h"
#include "py/objlist.h"
#include "py/objtuple.h"
#include "py/objstr.h"
#include "py/objint.h"
#include "py/objtype.h"
#include "py/stream.h"
#include "py/smallint.h"
#include "py/runtime.h"
#include "shared/runtime/pyexec.h"

#define INT_TO_STR_EX(number) #number
#define INT_TO_STR(number) INT_TO_STR_EX(number)

#ifdef CONFIG_OTA_WEB_USE_HTTPS
#define OTA_PROTOCOL "https"
#else
#define OTA_PROTOCOL "http"
#endif

#if defined(CONFIG_DEFAULT_DISPLAY_ORIENTATION_PORTRAIT)
#define DEFAULT_ORIENTATION 90
#elif defined(CONFIG_DEFAULT_DISPLAY_ORIENTATION_REVERSE_LANDSCAPE)
#define DEFAULT_ORIENTATION 180
#elif defined(CONFIG_DEFAULT_DISPLAY_ORIENTATION_REVERSE_PORTRAIT)
#define DEFAULT_ORIENTATION 270
#else
#define DEFAULT_ORIENTATION 0
#endif

static const MP_DEFINE_STR_OBJ( info_firmware_name_obj, CONFIG_INFO_FIRMWARE_NAME );
static const MP_DEFINE_STR_OBJ( info_hardware_name_obj, CONFIG_INFO_HARDWARE_NAME );
static const MP_DEFINE_STR_OBJ( info_hardware_folder_obj, CONFIG_MICROPY_FROZEN_MANIFEST );
static const MP_DEFINE_STR_OBJ( ota_web_server_obj, CONFIG_OTA_WEB_SERVER );
static const MP_DEFINE_STR_OBJ( ota_web_port_obj, INT_TO_STR(CONFIG_OTA_WEB_PORT) );
static const MP_DEFINE_STR_OBJ( ota_web_protocol_obj, OTA_PROTOCOL );
static const MP_DEFINE_STR_OBJ( ota_web_path_obj, CONFIG_OTA_WEB_PATH );
static const MP_DEFINE_STR_OBJ( ota_web_version_path_obj, CONFIG_OTA_WEB_VERSION_PATH );
static const MP_DEFINE_STR_OBJ( info_woezel_web_server_obj, CONFIG_WOEZEL_WEB_SERVER );
static const MP_DEFINE_STR_OBJ( info_hardware_woezel_name_obj, CONFIG_INFO_HARDWARE_WOEZEL_NAME );
static const MP_DEFINE_STR_OBJ( wifi_ssid_obj, CONFIG_WIFI_SSID );
static const MP_DEFINE_STR_OBJ( wifi_pass_obj, CONFIG_WIFI_PASSWORD );

static const mp_rom_map_elem_t consts_module_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR_INFO_FIRMWARE_NAME ), MP_ROM_PTR( &info_firmware_name_obj ) },
{ MP_ROM_QSTR(MP_QSTR_INFO_FIRMWARE_BUILD ), MP_ROM_INT( CONFIG_INFO_FIRMWARE_BUILD ) },
{ MP_ROM_QSTR(MP_QSTR_INFO_HARDWARE_NAME ), MP_ROM_PTR( &info_hardware_name_obj ) },
{ MP_ROM_QSTR(MP_QSTR_INFO_HARDWARE_FOLDER ), MP_ROM_PTR( &info_hardware_folder_obj ) },
{ MP_ROM_QSTR(MP_QSTR_WOEZEL_WEB_SERVER ), MP_ROM_PTR( &info_woezel_web_server_obj ) },
{ MP_ROM_QSTR(MP_QSTR_INFO_HARDWARE_WOEZEL_NAME ), MP_ROM_PTR( &info_hardware_woezel_name_obj ) },
{ MP_ROM_QSTR(MP_QSTR_OTA_WEB_SERVER ), MP_ROM_PTR( &ota_web_server_obj ) },
{ MP_ROM_QSTR(MP_QSTR_OTA_WEB_PORT ), MP_ROM_PTR( &ota_web_port_obj ) },
{ MP_ROM_QSTR(MP_QSTR_OTA_WEB_PROTOCOL ), MP_ROM_PTR( &ota_web_protocol_obj ) },
{ MP_ROM_QSTR(MP_QSTR_OTA_WEB_PATH ), MP_ROM_PTR( &ota_web_path_obj ) },
{ MP_ROM_QSTR(MP_QSTR_OTA_WEB_VERSION_PATH ), MP_ROM_PTR( &ota_web_version_path_obj ) },
{ MP_ROM_QSTR(MP_QSTR_WIFI_SSID ), MP_ROM_PTR( &wifi_ssid_obj ) },
{ MP_ROM_QSTR(MP_QSTR_WIFI_PASSWORD ), MP_ROM_PTR( &wifi_pass_obj ) },
{ MP_ROM_QSTR(MP_QSTR_DEFAULT_ORIENTATION ), MP_ROM_INT( DEFAULT_ORIENTATION ) },
};

static MP_DEFINE_CONST_DICT(consts_module_globals, consts_module_globals_table);

const mp_obj_module_t consts_module = {
.base = { &mp_type_module },
.globals = (mp_obj_dict_t*)&consts_module_globals,
};
MP_REGISTER_MODULE(MP_QSTR_consts, consts_module);
19 changes: 19 additions & 0 deletions components/driver_badge_bsp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
if(CONFIG_DRIVER_BADGE_BSP_ENABLE)
set(srcs
"driver_badge_bsp.c"
)
set(includes
"include"
)
else()
set(srcs "")
set(includes
""
)
endif()

idf_component_register(
SRCS "${srcs}"
INCLUDE_DIRS ${includes}
REQUIRES micropython badge-bsp
)
6 changes: 6 additions & 0 deletions components/driver_badge_bsp/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
menu "Driver: Badge BSP display"
config DRIVER_BADGE_BSP_ENABLE
bool "Enable the Badge BSP display driver"
default n

endmenu
Loading