refactor(examples): reformat peripheral examples with astyle_py

This commit is contained in:
morris
2023-09-28 09:43:12 +08:00
parent 1b2484214c
commit b12e250b2c
79 changed files with 677 additions and 703 deletions

View File

@@ -75,8 +75,8 @@ typedef enum {
static const char TAG[] = "example_slave";
static int s_job = JOB_IDLE;
DMA_ATTR uint8_t data_to_send[BUFFER_SIZE] = {0x97, 0x84, 0x43, 0x67, 0xc1, 0xdd, 0xff, 0x01, 0x02, 0x03, 0x04, 0x05, 0xff, 0xee, 0xdd, 0xcc, 0xbb, 0xaa, 0x99, 0x88, 0x77, 0x56, 0x55, 0x44, 0x33 ,0x22, 0x11, 0x00 };
DMA_ATTR uint8_t data_to_recv[BUFFER_SIZE] = {0x97, 0x84, 0x43, 0x67, 0xc1, 0xdd, 0xff, 0x01, 0x02, 0x03, 0x04, 0x05, 0xff, 0xee, 0xdd, 0xcc, 0xbb, 0xaa, 0x99, 0x88, 0x77, 0x56, 0x55, 0x44, 0x33 ,0x22, 0x11, 0x00 };
DMA_ATTR uint8_t data_to_send[BUFFER_SIZE] = {0x97, 0x84, 0x43, 0x67, 0xc1, 0xdd, 0xff, 0x01, 0x02, 0x03, 0x04, 0x05, 0xff, 0xee, 0xdd, 0xcc, 0xbb, 0xaa, 0x99, 0x88, 0x77, 0x56, 0x55, 0x44, 0x33, 0x22, 0x11, 0x00 };
DMA_ATTR uint8_t data_to_recv[BUFFER_SIZE] = {0x97, 0x84, 0x43, 0x67, 0xc1, 0xdd, 0xff, 0x01, 0x02, 0x03, 0x04, 0x05, 0xff, 0xee, 0xdd, 0xcc, 0xbb, 0xaa, 0x99, 0x88, 0x77, 0x56, 0x55, 0x44, 0x33, 0x22, 0x11, 0x00 };
static const char job_desc[][32] = {
"JOB_IDLE",
@@ -85,22 +85,27 @@ static const char job_desc[][32] = {
"JOB_WRITE_REG",
};
//reset counters of the slave hardware, and clean the receive buffer (normally they should be sent back to the host)
static esp_err_t slave_reset(void)
{
esp_err_t ret;
sdio_slave_stop();
ret = sdio_slave_reset();
if (ret != ESP_OK) return ret;
if (ret != ESP_OK) {
return ret;
}
ret = sdio_slave_start();
if (ret != ESP_OK) return ret;
if (ret != ESP_OK) {
return ret;
}
//Since the buffer will not be sent any more, we return them back to receving driver
while(1) {
while (1) {
sdio_slave_buf_handle_t handle;
ret = sdio_slave_send_get_finished(&handle, 0);
if (ret != ESP_OK) break;
if (ret != ESP_OK) {
break;
}
ret = sdio_slave_recv_load_buf(handle);
ESP_ERROR_CHECK(ret);
}
@@ -110,12 +115,14 @@ static esp_err_t slave_reset(void)
//sent interrupts to the host in turns
static esp_err_t task_hostint(void)
{
for(int i = 0; i < 8; i++) {
for (int i = 0; i < 8; i++) {
ESP_LOGV(TAG, "send intr: %d", i);
sdio_slave_send_host_int(i);
//check reset for quick response to RESET signal
if (s_job & JOB_RESET) break;
vTaskDelay(500/portTICK_PERIOD_MS);
if (s_job & JOB_RESET) {
break;
}
vTaskDelay(500 / portTICK_PERIOD_MS);
}
return ESP_OK;
}
@@ -127,7 +134,7 @@ static esp_err_t task_write_reg(void)
//the host write REG1, the slave should write its registers according to value of REG1
uint8_t read = sdio_slave_read_reg(1);
for (int i = 0; i < 60; i++) {
sdio_slave_write_reg(SLAVE_ADDR(i), read + 3*i);
sdio_slave_write_reg(SLAVE_ADDR(i), read + 3 * i);
}
uint8_t reg[60] = {0};
for (int i = 0; i < 60; i++) {
@@ -144,11 +151,11 @@ static esp_err_t task_write_reg(void)
static void event_cb(uint8_t pos)
{
ESP_EARLY_LOGD(TAG, "event: %d", pos);
switch(pos) {
case 0:
s_job = sdio_slave_read_reg(0);
sdio_slave_write_reg(0, JOB_IDLE);
break;
switch (pos) {
case 0:
s_job = sdio_slave_read_reg(0);
sdio_slave_write_reg(0, JOB_IDLE);
break;
}
}
@@ -185,7 +192,7 @@ void app_main(void)
sdio_slave_write_reg(0, JOB_IDLE);
for(int i = 0; i < BUFFER_NUM; i++) {
for (int i = 0; i < BUFFER_NUM; i++) {
sdio_slave_buf_handle_t handle = sdio_slave_recv_register_buf(buffer[i]);
assert(handle != NULL);
@@ -194,21 +201,21 @@ void app_main(void)
}
sdio_slave_set_host_intena(SDIO_SLAVE_HOSTINT_SEND_NEW_PACKET |
SDIO_SLAVE_HOSTINT_BIT0 |
SDIO_SLAVE_HOSTINT_BIT1 |
SDIO_SLAVE_HOSTINT_BIT2 |
SDIO_SLAVE_HOSTINT_BIT3 |
SDIO_SLAVE_HOSTINT_BIT4 |
SDIO_SLAVE_HOSTINT_BIT5 |
SDIO_SLAVE_HOSTINT_BIT6 |
SDIO_SLAVE_HOSTINT_BIT7
);
SDIO_SLAVE_HOSTINT_BIT0 |
SDIO_SLAVE_HOSTINT_BIT1 |
SDIO_SLAVE_HOSTINT_BIT2 |
SDIO_SLAVE_HOSTINT_BIT3 |
SDIO_SLAVE_HOSTINT_BIT4 |
SDIO_SLAVE_HOSTINT_BIT5 |
SDIO_SLAVE_HOSTINT_BIT6 |
SDIO_SLAVE_HOSTINT_BIT7
);
sdio_slave_start();
ESP_LOGI(TAG, EV_STR("slave ready"));
for(;;) {
for (;;) {
const TickType_t non_blocking = 0, blocking = portMAX_DELAY;
sdio_slave_buf_handle_t recv_queue[BUFFER_NUM];
int packet_size = 0;
@@ -266,7 +273,7 @@ void app_main(void)
}
// if there's finished sending desc, return the buffer to receiving driver
for(;;){
for (;;) {
void* send_args = NULL;
ret = sdio_slave_send_get_finished(&send_args, 0);
@@ -281,12 +288,12 @@ void app_main(void)
}
if (s_job != 0) {
for(int i = 0; i < 8; i++) {
for (int i = 0; i < 8; i++) {
if (s_job & BIT(i)) {
ESP_LOGI(TAG, EV_STR("%s"), job_desc[i+1]);
ESP_LOGI(TAG, EV_STR("%s"), job_desc[i + 1]);
s_job &= ~BIT(i);
switch(BIT(i)) {
switch (BIT(i)) {
case JOB_SEND_INT:
ret = task_hostint();
ESP_ERROR_CHECK(ret);