Skip to content
Snippets Groups Projects
Commit 72915b88 authored by moon2's avatar moon2 :speech_balloon: Committed by q3k
Browse files

crude hardware revision config, captouch working

parent 81003bcd
No related branches found
No related tags found
No related merge requests found
#include "badge23/audio.h" #include "badge23/audio.h"
#include "badge23/synth.h" #include "badge23/synth.h"
#include "badge23/scope.h" #include "badge23/scope.h"
#include "../../../revision_config.h"
#include "driver/i2s.h" #include "driver/i2s.h"
#include "driver/i2c.h" #include "driver/i2c.h"
...@@ -17,8 +18,13 @@ ...@@ -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 */ #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) static uint8_t max98091_i2c_read(const uint8_t reg)
{ {
const uint8_t tx[] = {reg}; const uint8_t tx[] = {reg};
...@@ -26,7 +32,6 @@ static uint8_t max98091_i2c_read(const uint8_t 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); 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]; return rx[0];
} }
#endif
static esp_err_t max98091_i2c_write(const uint8_t reg, const uint8_t data) static esp_err_t max98091_i2c_write(const uint8_t reg, const uint8_t data)
{ {
...@@ -110,14 +115,9 @@ static void init_codec() ...@@ -110,14 +115,9 @@ static void init_codec()
ESP_ERROR_CHECK(max98091_i2c_write(0x3D, 1<<7)); // jack detect enable ESP_ERROR_CHECK(max98091_i2c_write(0x3D, 1<<7)); // jack detect enable
} }
static void i2s_init(void){
static void audio_player_task(void* arg); init_codec();
vTaskDelay(100 / portTICK_PERIOD_MS); // dunno if necessary
#define DMA_BUFFER_SIZE 64
#define DMA_BUFFER_COUNT 2
#define I2S_PORT 0
static void i2s_init_rev1(void){
static const i2s_config_t i2s_config = { static const i2s_config_t i2s_config = {
.mode = I2S_MODE_MASTER | I2S_MODE_TX, .mode = I2S_MODE_MASTER | I2S_MODE_TX,
...@@ -125,18 +125,18 @@ static void i2s_init_rev1(void){ ...@@ -125,18 +125,18 @@ static void i2s_init_rev1(void){
.bits_per_sample = 16, .bits_per_sample = 16,
.channel_format = I2S_CHANNEL_FMT_RIGHT_LEFT, .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,
.communication_format = I2S_COMM_FORMAT_I2S | I2S_COMM_FORMAT_I2S_MSB, //^...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 .intr_alloc_flags = 0, // default interrupt priority
.dma_buf_count = DMA_BUFFER_COUNT, .dma_buf_count = DMA_BUFFER_COUNT,
.dma_buf_len = DMA_BUFFER_SIZE, .dma_buf_len = DMA_BUFFER_SIZE,
.use_apll = false .use_apll = false
}; };
static const i2s_pin_config_t pin_config = { static const i2s_pin_config_t pin_config = {
.bck_io_num = 13, .bck_io_num = 10,
.mck_io_num = 11, .mck_io_num = 18,
.ws_io_num = 12, .ws_io_num = 11,
.data_out_num = 14, .data_out_num = 12,
.data_in_num = I2S_PIN_NO_CHANGE .data_in_num = I2S_PIN_NO_CHANGE
}; };
i2s_driver_install(I2S_PORT, &i2s_config, 0, NULL); i2s_driver_install(I2S_PORT, &i2s_config, 0, NULL);
...@@ -144,8 +144,11 @@ static void i2s_init_rev1(void){ ...@@ -144,8 +144,11 @@ static void i2s_init_rev1(void){
i2s_set_pin(I2S_PORT, &pin_config); 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 = { static const i2s_config_t i2s_config = {
.mode = I2S_MODE_MASTER | I2S_MODE_TX, .mode = I2S_MODE_MASTER | I2S_MODE_TX,
...@@ -153,25 +156,25 @@ static void i2s_init_rev4(void){ ...@@ -153,25 +156,25 @@ static void i2s_init_rev4(void){
.bits_per_sample = 16, .bits_per_sample = 16,
.channel_format = I2S_CHANNEL_FMT_RIGHT_LEFT, .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...? .communication_format = I2S_COMM_FORMAT_I2S | I2S_COMM_FORMAT_I2S_MSB,
.intr_alloc_flags = 0, // default interrupt priority .intr_alloc_flags = 0, // default interrupt priority
.dma_buf_count = DMA_BUFFER_COUNT, .dma_buf_count = DMA_BUFFER_COUNT,
.dma_buf_len = DMA_BUFFER_SIZE, .dma_buf_len = DMA_BUFFER_SIZE,
.use_apll = false .use_apll = false
}; };
static const i2s_pin_config_t pin_config = { static const i2s_pin_config_t pin_config = {
.bck_io_num = 10, .bck_io_num = 13,
.mck_io_num = 18, .mck_io_num = 11,
.ws_io_num = 11, .ws_io_num = 12,
.data_out_num = 12, .data_out_num = 14,
.data_in_num = I2S_PIN_NO_CHANGE .data_in_num = I2S_PIN_NO_CHANGE
}; };
i2s_driver_install(I2S_PORT, &i2s_config, 0, NULL); i2s_driver_install(I2S_PORT, &i2s_config, 0, NULL);
i2s_set_pin(I2S_PORT, &pin_config); i2s_set_pin(I2S_PORT, &pin_config);
} }
#endif
typedef struct _audio_source_t{ typedef struct _audio_source_t{
void * render_data; void * render_data;
...@@ -255,13 +258,8 @@ uint16_t count_audio_sources(){ ...@@ -255,13 +258,8 @@ uint16_t count_audio_sources(){
} }
static void _audio_init(void) { 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); init_scope(241);
i2s_init_rev4(); i2s_init();
//ESP_ERROR_CHECK(i2s_channel_enable(tx_chan)); //ESP_ERROR_CHECK(i2s_channel_enable(tx_chan));
TaskHandle_t handle; TaskHandle_t handle;
xTaskCreate(&audio_player_task, "Audio player", 3000, NULL, configMAX_PRIORITIES - 1, &handle); xTaskCreate(&audio_player_task, "Audio player", 3000, NULL, configMAX_PRIORITIES - 1, &handle);
......
...@@ -2,8 +2,22 @@ ...@@ -2,8 +2,22 @@
//#include <string.h> //#include <string.h>
#include "esp_log.h" #include "esp_log.h"
#include "driver/i2c.h" #include "driver/i2c.h"
#include "../../../revision_config.h"
#include <stdint.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"; static const char *TAG = "captouch";
...@@ -25,8 +39,8 @@ struct ad714x_chip { ...@@ -25,8 +39,8 @@ struct ad714x_chip {
int stages; 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_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=10}; 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) 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) ...@@ -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 read_captouch(){
uint16_t petals = 0; uint16_t petals = 0;
uint16_t top = pressed_top; uint16_t top = pressed_top;
uint16_t bot = pressed_bot; uint16_t bot = pressed_bot;
for(int i=0; i<12; i++) { for(int i=0; i<top_stages; i++) {
if(top & (1 << i)) { if(top & (1 << i)) {
petals |= (1<<top_map[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)) { if(bot & (1 << i)) {
petals |= (1<<bot_map[i]); petals |= (1<<bot_map[i]);
} }
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
#include "badge23/audio.h" #include "badge23/audio.h"
#include "badge23/leds.h" #include "badge23/leds.h"
#include "badge23/display.h" #include "badge23/display.h"
#include "../../../revision_config.h"
#include "esp_log.h" #include "esp_log.h"
#include "driver/i2c.h" #include "driver/i2c.h"
...@@ -19,8 +20,15 @@ static const char *TAG = "espan"; ...@@ -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_TX_BUF_DISABLE 0 /*!< I2C master doesn't need buffer */
#define I2C_MASTER_RX_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_SDA 2
#define CONFIG_I2C_MASTER_SCL 1 #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) static esp_err_t i2c_master_init(void)
{ {
...@@ -50,16 +58,16 @@ void os_app_main(void) ...@@ -50,16 +58,16 @@ void os_app_main(void)
set_global_vol_dB(-90); set_global_vol_dB(-90);
audio_init(); audio_init();
//leds_init(); //leds_init();
//captouch_init(); captouch_init();
vTaskDelay(2000 / portTICK_PERIOD_MS); vTaskDelay(2000 / portTICK_PERIOD_MS);
set_global_vol_dB(0); set_global_vol_dB(0);
//display_init(); //display_init();
while(1) { while(1) {
//manual_captouch_readout(1); manual_captouch_readout(1);
vTaskDelay((CAPTOUCH_POLLING_PERIOD) / portTICK_PERIOD_MS); vTaskDelay((CAPTOUCH_POLLING_PERIOD) / portTICK_PERIOD_MS);
//manual_captouch_readout(0); manual_captouch_readout(0);
vTaskDelay((CAPTOUCH_POLLING_PERIOD) / portTICK_PERIOD_MS); vTaskDelay((CAPTOUCH_POLLING_PERIOD) / portTICK_PERIOD_MS);
//display_draw_scope(); //display_draw_scope();
} }
......
#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
*/
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment