firmware: Move serial number code to main

This commit is contained in:
Jack O'Sullivan 2024-12-11 19:02:24 +00:00
parent 4817c80df3
commit 0cdaefc992
3 changed files with 12 additions and 9 deletions

View File

@ -9,5 +9,7 @@
#define LCD_HRES 800
#define LCD_VRES 480
extern char val_dev_serial[13];
extern i2c_master_bus_handle_t i2c_bus_handle;
extern i2c_master_dev_handle_t exio_cfg_handle, exio_o_handle;

View File

@ -1,7 +1,6 @@
#include <inttypes.h>
#include "esp_log.h"
#include "esp_mac.h"
#include "tinyusb.h"
#include "class/hid/hid_device.h"
@ -38,7 +37,6 @@ const tusb_desc_device_t val_usb_dev_descriptor = {
.bNumConfigurations = 0x01,
};
char val_dev_serial[13];
const char* val_usb_string_descriptor[5] = {
// 0: supported language is English (0x0409)
(char[]){0x09, 0x04},
@ -101,13 +99,6 @@ void tud_hid_set_report_cb(uint8_t instance, uint8_t report_id, hid_report_type_
void val_usb_init(void) {
ESP_LOGI(TAG, "Initializing USB");
// Use MAC address for serial number
uint8_t mac[6] = { 0 };
ESP_ERROR_CHECK(esp_read_mac(mac, ESP_MAC_EFUSE_FACTORY));
snprintf(
val_dev_serial, sizeof(val_dev_serial),
"%02x%02x%02x%02x%02x%02x", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
const tinyusb_config_t cfg = {
.device_descriptor = &val_usb_dev_descriptor,
.string_descriptor = val_usb_string_descriptor,

View File

@ -6,6 +6,7 @@
#include "esp_err.h"
#include "esp_log.h"
#include "esp_mac.h"
#include "esp_lcd_panel_ops.h"
#include "driver/i2c_master.h"
@ -18,6 +19,8 @@
static const char *TAG = "valconomy";
char val_dev_serial[13];
i2c_master_bus_handle_t i2c_bus_handle;
i2c_master_dev_handle_t exio_cfg_handle, exio_o_handle;
@ -46,6 +49,13 @@ static void val_i2c_master_init(void) {
}
void app_main(void) {
// Use MAC address for serial number
uint8_t mac[6] = { 0 };
ESP_ERROR_CHECK(esp_read_mac(mac, ESP_MAC_EFUSE_FACTORY));
snprintf(
val_dev_serial, sizeof(val_dev_serial),
"%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
val_i2c_master_init();
val_usb_init();