diff --git a/components/badge23/audio.c b/components/badge23/audio.c index 7985bf696f9f35e572ec463f5b77e3d2b7ab2fe8..ce7fe753eac96d330b5e8f8e6c9a96ba5149f01a 100644 --- a/components/badge23/audio.c +++ b/components/badge23/audio.c @@ -1,6 +1,7 @@ #include "badge23/audio.h" #include "badge23/synth.h" #include "badge23/scope.h" +#include "../../../revision_config.h" #include "driver/i2s.h" #include "driver/i2c.h" @@ -17,8 +18,13 @@ #define I2C_MASTER_NUM 0 /*!< I2C master i2c port number, the number of i2c peripheral interfaces available will depend on the chip */ +static void audio_player_task(void* arg); + +#define DMA_BUFFER_SIZE 64 +#define DMA_BUFFER_COUNT 2 +#define I2S_PORT 0 -#if 1 +#ifdef HARDWARE_REVISION_04 static uint8_t max98091_i2c_read(const uint8_t reg) { const uint8_t tx[] = {reg}; @@ -26,7 +32,6 @@ static uint8_t max98091_i2c_read(const uint8_t reg) esp_err_t ret = i2c_master_write_read_device(I2C_MASTER_NUM, 0x10, tx, sizeof(tx), rx, sizeof(rx), TIMEOUT_MS / portTICK_PERIOD_MS); return rx[0]; } -#endif static esp_err_t max98091_i2c_write(const uint8_t reg, const uint8_t data) { @@ -110,14 +115,9 @@ static void init_codec() ESP_ERROR_CHECK(max98091_i2c_write(0x3D, 1<<7)); // jack detect enable } - -static void audio_player_task(void* arg); - -#define DMA_BUFFER_SIZE 64 -#define DMA_BUFFER_COUNT 2 -#define I2S_PORT 0 - -static void i2s_init_rev1(void){ +static void i2s_init(void){ + init_codec(); + vTaskDelay(100 / portTICK_PERIOD_MS); // dunno if necessary static const i2s_config_t i2s_config = { .mode = I2S_MODE_MASTER | I2S_MODE_TX, @@ -125,18 +125,18 @@ static void i2s_init_rev1(void){ .bits_per_sample = 16, .channel_format = I2S_CHANNEL_FMT_RIGHT_LEFT, //.communication_format = I2S_COMM_FORMAT_I2S | I2S_COMM_FORMAT_I2S_MSB, - - .communication_format = I2S_COMM_FORMAT_I2S | I2S_COMM_FORMAT_I2S_MSB, + .communication_format = I2S_COMM_FORMAT_I2S | I2S_COMM_FORMAT_I2S_LSB, + //^...technically wrong but works...? in idf v5 it's msb but don't try that late at night .intr_alloc_flags = 0, // default interrupt priority .dma_buf_count = DMA_BUFFER_COUNT, .dma_buf_len = DMA_BUFFER_SIZE, .use_apll = false }; static const i2s_pin_config_t pin_config = { - .bck_io_num = 13, - .mck_io_num = 11, - .ws_io_num = 12, - .data_out_num = 14, + .bck_io_num = 10, + .mck_io_num = 18, + .ws_io_num = 11, + .data_out_num = 12, .data_in_num = I2S_PIN_NO_CHANGE }; i2s_driver_install(I2S_PORT, &i2s_config, 0, NULL); @@ -144,8 +144,11 @@ static void i2s_init_rev1(void){ i2s_set_pin(I2S_PORT, &pin_config); } +#endif -static void i2s_init_rev4(void){ + +#ifdef HARDWARE_REVISION_01 +static void i2s_init(void){ static const i2s_config_t i2s_config = { .mode = I2S_MODE_MASTER | I2S_MODE_TX, @@ -153,25 +156,25 @@ static void i2s_init_rev4(void){ .bits_per_sample = 16, .channel_format = I2S_CHANNEL_FMT_RIGHT_LEFT, //.communication_format = I2S_COMM_FORMAT_I2S | I2S_COMM_FORMAT_I2S_MSB, - .communication_format = I2S_COMM_FORMAT_I2S | I2S_COMM_FORMAT_I2S_LSB, - //^...technically wrong but works...? + + .communication_format = I2S_COMM_FORMAT_I2S | I2S_COMM_FORMAT_I2S_MSB, .intr_alloc_flags = 0, // default interrupt priority .dma_buf_count = DMA_BUFFER_COUNT, .dma_buf_len = DMA_BUFFER_SIZE, .use_apll = false }; static const i2s_pin_config_t pin_config = { - .bck_io_num = 10, - .mck_io_num = 18, - .ws_io_num = 11, - .data_out_num = 12, + .bck_io_num = 13, + .mck_io_num = 11, + .ws_io_num = 12, + .data_out_num = 14, .data_in_num = I2S_PIN_NO_CHANGE }; i2s_driver_install(I2S_PORT, &i2s_config, 0, NULL); i2s_set_pin(I2S_PORT, &pin_config); - } +#endif typedef struct _audio_source_t{ void * render_data; @@ -255,13 +258,8 @@ uint16_t count_audio_sources(){ } static void _audio_init(void) { - vTaskDelay(1000 / portTICK_PERIOD_MS); - printf("hewoooo\n"); - init_codec(); - printf("awa\n"); - vTaskDelay(1000 / portTICK_PERIOD_MS); init_scope(241); - i2s_init_rev4(); + i2s_init(); //ESP_ERROR_CHECK(i2s_channel_enable(tx_chan)); TaskHandle_t handle; xTaskCreate(&audio_player_task, "Audio player", 3000, NULL, configMAX_PRIORITIES - 1, &handle); diff --git a/components/badge23/captouch.c b/components/badge23/captouch.c index 36f14c2c74b7ca001d33c578301d8f9bb603da5b..f82e97897f235c88a02597dd1bfc9aa6304c7bb2 100644 --- a/components/badge23/captouch.c +++ b/components/badge23/captouch.c @@ -2,8 +2,22 @@ //#include <string.h> #include "esp_log.h" #include "driver/i2c.h" +#include "../../../revision_config.h" #include <stdint.h> +#ifdef HARDWARE_REVISION_04 +static const uint8_t top_map[] = {1, 1, 3, 3, 5, 5, 7, 7, 9, 9, 8, 8}; //flipped top and bottom from bootstrap reference +static const uint8_t top_stages = 12; +static const uint8_t bot_map[] = {0, 0, 0, 2, 2, 2, 6, 6, 6, 4, 4, 4}; //idk y :~) +static const uint8_t bottom_stages = 12; +#endif + +#ifdef HARDWARE_REVISION_01 +static const uint8_t top_map[] = {2, 2, 2, 0, 0, 8, 8, 8, 6, 6, 4, 4}; +static const uint8_t top_stages = 12; +static const uint8_t bot_map[] = {1, 1, 3, 3, 5, 5, 7, 7, 9, 9}; +static const uint8_t bottom_stages = 10; +#endif static const char *TAG = "captouch"; @@ -25,8 +39,8 @@ struct ad714x_chip { int stages; }; -static const struct ad714x_chip chip_top = {.addr = AD7147_BASE_ADDR + 1, .gpio = 48, .afe_offsets = {24, 12, 16, 33, 30, 28, 31, 27, 22, 24, 18, 19, }, .stages=12}; -static const struct ad714x_chip chip_bot = {.addr = AD7147_BASE_ADDR, .gpio = 3, .afe_offsets = {3, 2, 1, 1 ,1, 1, 1, 1, 2, 3}, .stages=10}; +static const struct ad714x_chip chip_top = {.addr = AD7147_BASE_ADDR + 1, .gpio = 48, .afe_offsets = {24, 12, 16, 33, 30, 28, 31, 27, 22, 24, 18, 19, }, .stages=top_stages}; +static const struct ad714x_chip chip_bot = {.addr = AD7147_BASE_ADDR, .gpio = 3, .afe_offsets = {3, 2, 1, 1 ,1, 1, 1, 1, 2, 3}, .stages=bottom_stages}; static esp_err_t ad714x_i2c_write(const struct ad714x_chip *chip, const uint16_t reg, const uint16_t data) { @@ -179,21 +193,18 @@ void gpio_event_handler(void* arg) } } -static uint8_t top_map[] = {2, 2, 2, 0, 0, 8, 8, 8, 6, 6, 4, 4}; -static uint8_t bot_map[] = {1, 1, 3, 3, 5, 5, 7, 7, 9, 9}; - uint16_t read_captouch(){ uint16_t petals = 0; uint16_t top = pressed_top; uint16_t bot = pressed_bot; - for(int i=0; i<12; i++) { + for(int i=0; i<top_stages; i++) { if(top & (1 << i)) { petals |= (1<<top_map[i]); } } - for(int i=0; i<10; i++) { + for(int i=0; i<bottom_stages; i++) { if(bot & (1 << i)) { petals |= (1<<bot_map[i]); } diff --git a/components/badge23/espan.c b/components/badge23/espan.c index 6e97c8364129a492aaec6129d1eeeedd1f929a5c..f83f78f890da3cbf3cc9b03a0e6292178316a734 100644 --- a/components/badge23/espan.c +++ b/components/badge23/espan.c @@ -2,6 +2,7 @@ #include "badge23/audio.h" #include "badge23/leds.h" #include "badge23/display.h" +#include "../../../revision_config.h" #include "esp_log.h" #include "driver/i2c.h" @@ -19,8 +20,15 @@ static const char *TAG = "espan"; #define I2C_MASTER_TX_BUF_DISABLE 0 /*!< I2C master doesn't need buffer */ #define I2C_MASTER_RX_BUF_DISABLE 0 /*!< I2C master doesn't need buffer */ +#ifdef HARDWARE_REVISION_04 #define CONFIG_I2C_MASTER_SDA 2 #define CONFIG_I2C_MASTER_SCL 1 +#endif + +#ifdef HARDWARE_REVISION_01 +#define CONFIG_I2C_MASTER_SDA 10 +#define CONFIG_I2C_MASTER_SCL 9 +#endif static esp_err_t i2c_master_init(void) { @@ -50,16 +58,16 @@ void os_app_main(void) set_global_vol_dB(-90); audio_init(); //leds_init(); - //captouch_init(); + captouch_init(); vTaskDelay(2000 / portTICK_PERIOD_MS); set_global_vol_dB(0); //display_init(); while(1) { - //manual_captouch_readout(1); + manual_captouch_readout(1); vTaskDelay((CAPTOUCH_POLLING_PERIOD) / portTICK_PERIOD_MS); - //manual_captouch_readout(0); + manual_captouch_readout(0); vTaskDelay((CAPTOUCH_POLLING_PERIOD) / portTICK_PERIOD_MS); //display_draw_scope(); } diff --git a/revision_config.h b/revision_config.h new file mode 100644 index 0000000000000000000000000000000000000000..6ddfea01704b03ff38381b8dda6bce29536c0d0c --- /dev/null +++ b/revision_config.h @@ -0,0 +1,11 @@ +#define HARDWARE_REVISION_04 +/* visual identifiers: + * - sticker with 04XX (XX being arbitrary digits) on the back + */ + +//#define HARDWARE_REVISION_01 +/* visual identifiers: + * - no line in/line out jacks + * - white bottom board + * - usb c jack points towards side of leaf + */