diff options
Diffstat (limited to 'fw')
-rw-r--r-- | fw/esp32/components/eos/cell_pcm.c | 309 | ||||
-rw-r--r-- | fw/esp32/components/eos/i2c.c | 82 | ||||
-rw-r--r-- | fw/esp32/components/eos/include/_net.h | 1 | ||||
-rw-r--r-- | fw/esp32/components/eos/include/i2c.h | 9 | ||||
-rw-r--r-- | fw/fe310/eos/dev/Makefile | 11 | ||||
-rw-r--r-- | fw/fe310/eos/dev/aon.c | 29 | ||||
-rw-r--r-- | fw/fe310/eos/dev/aon.h | 4 | ||||
-rw-r--r-- | fw/fe310/eos/dev/batt.c | 54 | ||||
-rw-r--r-- | fw/fe310/eos/dev/batt.h | 4 | ||||
-rw-r--r-- | fw/fe310/eos/dev/cam.h | 14 | ||||
-rw-r--r-- | fw/fe310/eos/dev/cam_def.h | 65 | ||||
-rw-r--r-- | fw/fe310/eos/dev/net.c | 41 | ||||
-rw-r--r-- | fw/fe310/eos/dev/net.h | 7 | ||||
-rw-r--r-- | fw/fe310/eos/dev/pwr.c | 48 | ||||
-rw-r--r-- | fw/fe310/eos/dev/pwr.h | 1 | ||||
-rw-r--r-- | fw/fe310/eos/dev/sdc_crypto.c | 8 | ||||
-rw-r--r-- | fw/fe310/eos/dev/sdc_crypto.h | 18 | ||||
-rw-r--r-- | fw/fe310/eos/dev/sdcard.c | 38 | ||||
-rw-r--r-- | fw/fe310/eos/dev/sdcard.h | 3 | ||||
-rw-r--r-- | fw/fe310/eos/net/pwr.c | 80 | ||||
-rw-r--r-- | fw/fe310/eos/net/pwr.h | 10 |
21 files changed, 307 insertions, 529 deletions
diff --git a/fw/esp32/components/eos/cell_pcm.c b/fw/esp32/components/eos/cell_pcm.c deleted file mode 100644 index b993021..0000000 --- a/fw/esp32/components/eos/cell_pcm.c +++ /dev/null @@ -1,309 +0,0 @@ -#include <stdlib.h> -#include <string.h> - -#include <freertos/FreeRTOS.h> -#include <freertos/semphr.h> -#include <freertos/task.h> -#include <freertos/queue.h> -#include <driver/i2s.h> -#include <driver/gpio.h> -#include <esp_log.h> - -#include "eos.h" -#include "net.h" -#include "msgq.h" -#include "cell.h" - -#define PCM_MIC_WM 128 -#define PCM_HOLD_CNT_TX 3 -#define PCM_HOLD_CNT_RX 3 -#define PCM_SIZE_BUFQ 4 -#define PCM_SIZE_BUF (PCM_MIC_WM * 4) - -#define PCM_GPIO_BCK 33 -#define PCM_GPIO_WS 4 -#define PCM_GPIO_DIN 34 -#define PCM_GPIO_DOUT 2 - -#define PCM_ETYPE_WRITE 1 - -static EOSBufQ pcm_buf_q; -static unsigned char *pcm_bufq_array[PCM_SIZE_BUFQ]; - -static EOSMsgQ pcm_evt_q; -static EOSMsgItem pcm_evtq_array[PCM_SIZE_BUFQ]; -static char pcm_hold_tx; -static char pcm_active = 0; - -static i2s_dev_t* I2S[I2S_NUM_MAX] = {&I2S0, &I2S1}; - -static QueueHandle_t i2s_queue; -static SemaphoreHandle_t mutex; - -static const char *TAG = "EOS PCM"; - -static void i2s_event_task(void *pvParameters) { - i2s_event_t event; - ssize_t hold_bytes_r = 0; - unsigned char *hold_buf = NULL; - char hold_cnt = 0; - - while (1) { - // Waiting for I2S event. - if (xQueueReceive(i2s_queue, &event, portMAX_DELAY)) { - switch (event.type) { - case I2S_EVENT_RX_DONE: { - ssize_t bytes_r; - size_t bytes_w; - uint16_t bytes_e; - unsigned char _type; - unsigned char *buf; - - if (!pcm_active) { - if (hold_buf) { - eos_net_free(hold_buf); - hold_buf = NULL; - } - break; - } - - // Event of I2S receiving data - if (!hold_cnt) { - buf = eos_net_alloc(); - buf[0] = EOS_CELL_MTYPE_VOICE | EOS_CELL_MTYPE_VOICE_PCM; - bytes_r = eos_cell_pcm_read(buf + 1, PCM_MIC_WM); - if (bytes_r < 0) { - ESP_LOGE(TAG, "*** I2S READ ERROR ***"); - eos_net_free(buf); - break; - } - eos_net_send(EOS_NET_MTYPE_CELL, buf, bytes_r + 1); - } else { - if (hold_buf == NULL) { - hold_buf = eos_net_alloc(); - hold_buf[0] = EOS_CELL_MTYPE_VOICE | EOS_CELL_MTYPE_VOICE_PCM; - hold_bytes_r = 0; - } - if (1 + hold_bytes_r + PCM_MIC_WM <= EOS_NET_SIZE_BUF) { - bytes_r = eos_cell_pcm_read(hold_buf + 1 + hold_bytes_r, PCM_MIC_WM); - if (bytes_r < 0) { - ESP_LOGE(TAG, "*** I2S READ ERROR ***"); - break; - } - hold_bytes_r += bytes_r; - } - hold_cnt--; - if (hold_cnt == 0) { - eos_net_send(EOS_NET_MTYPE_CELL, hold_buf, hold_bytes_r + 1); - hold_buf = NULL; - } - } - - buf = NULL; - xSemaphoreTake(mutex, portMAX_DELAY); - if (pcm_hold_tx && (eos_msgq_len(&pcm_evt_q) == PCM_HOLD_CNT_TX)) pcm_hold_tx = 0; - if (!pcm_hold_tx) eos_msgq_pop(&pcm_evt_q, &_type, &buf, &bytes_e); - xSemaphoreGive(mutex); - - if (buf) { - esp_err_t ret; - - ret = i2s_write(I2S_NUM_0, (const void *)buf, bytes_e, &bytes_w, 1000 / portTICK_RATE_MS); - xSemaphoreTake(mutex, portMAX_DELAY); - eos_bufq_push(&pcm_buf_q, buf); - xSemaphoreGive(mutex); - if (ret != ESP_OK) { - ESP_LOGE(TAG, "*** I2S WRITE ERROR ***"); - break; - } - } - break; - } - - case I2S_EVENT_DMA_ERROR: { - ESP_LOGE(TAG, "*** I2S DMA ERROR ***"); - break; - } - - case I2S_EVENT_MAX: { - hold_cnt = PCM_HOLD_CNT_RX; - break; - } - - default: - break; - } - } - } - vTaskDelete(NULL); -} - -void eos_cell_pcm_init(void) { - int i; - - i2s_config_t i2s_config = { - .mode = I2S_MODE_SLAVE | I2S_MODE_TX | I2S_MODE_RX, - .sample_rate = 32000, - .bits_per_sample = 32, - .channel_format = I2S_CHANNEL_FMT_ONLY_LEFT, - .communication_format = I2S_COMM_FORMAT_STAND_I2S, - .dma_buf_count = 4, - .dma_buf_len = PCM_MIC_WM, - .use_apll = true, - .fixed_mclk = 2048000 * 8, - .intr_alloc_flags = ESP_INTR_FLAG_LEVEL1 - }; - - i2s_pin_config_t pin_config = { - .bck_io_num = PCM_GPIO_BCK, - .ws_io_num = PCM_GPIO_WS, - .data_in_num = PCM_GPIO_DIN, - .data_out_num = PCM_GPIO_DOUT - }; - i2s_driver_install(I2S_NUM_0, &i2s_config, 10, &i2s_queue); //install and start i2s driver - i2s_stop(I2S_NUM_0); - i2s_set_pin(I2S_NUM_0, &pin_config); - gpio_matrix_in(pin_config.ws_io_num, I2S0I_WS_IN_IDX, 1); - gpio_matrix_in(pin_config.bck_io_num, I2S0I_BCK_IN_IDX, 1); - ESP_LOGI(TAG, "TX FIFO:%d TX CHAN:%d RX FIFO:%d RX CHAN:%d", I2S[I2S_NUM_0]->fifo_conf.tx_fifo_mod, I2S[I2S_NUM_0]->conf_chan.tx_chan_mod, I2S[I2S_NUM_0]->fifo_conf.rx_fifo_mod, I2S[I2S_NUM_0]->conf_chan.rx_chan_mod); - - I2S[I2S_NUM_0]->fifo_conf.tx_fifo_mod = 2; - I2S[I2S_NUM_0]->conf_chan.tx_chan_mod = 0; - - I2S[I2S_NUM_0]->fifo_conf.rx_fifo_mod = 3; - I2S[I2S_NUM_0]->conf_chan.rx_chan_mod = 1; - // I2S[I2S_NUM_0]->conf.tx_mono = 1; - I2S[I2S_NUM_0]->conf.rx_mono = 1; - // I2S[I2S_NUM_0]->timing.tx_dsync_sw = 1 - // I2S[I2S_NUM_0]->timing.rx_dsync_sw = 1 - // I2S[I2S_NUM_0]->conf.sig_loopback = 0; - - // I2S[I2S_NUM_0]->timing.tx_bck_in_inv = 1; - - eos_msgq_init(&pcm_evt_q, pcm_evtq_array, PCM_SIZE_BUFQ); - eos_bufq_init(&pcm_buf_q, pcm_bufq_array, PCM_SIZE_BUFQ); - for (i=0; i<PCM_SIZE_BUFQ; i++) { - eos_bufq_push(&pcm_buf_q, malloc(PCM_SIZE_BUF)); - } - - mutex = xSemaphoreCreateBinary(); - xSemaphoreGive(mutex); - - // Create a task to handle i2s event from ISR - xTaskCreate(i2s_event_task, "i2s_event", EOS_TASK_SSIZE_I2S, NULL, EOS_TASK_PRIORITY_I2S, NULL); - ESP_LOGI(TAG, "INIT"); -} - -ssize_t eos_cell_pcm_read(unsigned char *data, size_t size) { - static unsigned char buf[PCM_SIZE_BUF]; - size_t bytes_r; - esp_err_t ret; - int i; - - if (size > PCM_MIC_WM) return EOS_ERR; - - ret = i2s_read(I2S_NUM_0, (void *)buf, size * 4, &bytes_r, 1000 / portTICK_RATE_MS); - if (ret != ESP_OK) return EOS_ERR; - - for (i=0; i<size/2; i++) { - data[i * 2] = buf[i * 8 + 3]; - data[i * 2 + 1] = buf[i * 8 + 2]; - } - - return bytes_r / 4; -} - -static ssize_t pcm_expand(unsigned char *buf, unsigned char *data, size_t size) { - int i; - - if (size > PCM_MIC_WM) return EOS_ERR; - - memset(buf, 0, PCM_SIZE_BUF); - for (i=0; i<size/2; i++) { - buf[i * 8 + 3] = data[i * 2]; - buf[i * 8 + 2] = data[i * 2 + 1]; - } - - return size * 4; -} - -int eos_cell_pcm_push(unsigned char *data, size_t size) { - unsigned char *buf = NULL; - ssize_t esize; - int rv; - - if (size > PCM_MIC_WM) return EOS_ERR; - - xSemaphoreTake(mutex, portMAX_DELAY); - if (!pcm_active) { - xSemaphoreGive(mutex); - return EOS_ERR; - } - if (pcm_hold_tx && (eos_msgq_len(&pcm_evt_q) == PCM_HOLD_CNT_TX)) { - unsigned char _type; - uint16_t _len; - - eos_msgq_pop(&pcm_evt_q, &_type, &buf, &_len); - } else { - buf = eos_bufq_pop(&pcm_buf_q); - } - xSemaphoreGive(mutex); - - if (buf == NULL) return EOS_ERR_EMPTY; - - esize = pcm_expand(buf, data, size); - if (esize < 0) { - xSemaphoreTake(mutex, portMAX_DELAY); - eos_bufq_push(&pcm_buf_q, buf); - xSemaphoreGive(mutex); - return esize; - } - - xSemaphoreTake(mutex, portMAX_DELAY); - rv = eos_msgq_push(&pcm_evt_q, PCM_ETYPE_WRITE, buf, esize); - if (rv) eos_bufq_push(&pcm_buf_q, buf); - xSemaphoreGive(mutex); - - return rv; -} - -void eos_cell_pcm_start(void) { - i2s_event_t evt; - - xSemaphoreTake(mutex, portMAX_DELAY); - if (pcm_active) { - xSemaphoreGive(mutex); - return; - } - while (1) { - unsigned char _type; - unsigned char *buf; - uint16_t len; - - eos_msgq_pop(&pcm_evt_q, &_type, &buf, &len); - if (buf) { - eos_bufq_push(&pcm_buf_q, buf); - } else { - break; - } - } - pcm_active = 1; - pcm_hold_tx = 1; - xSemaphoreGive(mutex); - - evt.type = I2S_EVENT_MAX; /* my type */ - xQueueSend(i2s_queue, &evt, portMAX_DELAY); - i2s_zero_dma_buffer(I2S_NUM_0); - i2s_start(I2S_NUM_0); -} - -void eos_cell_pcm_stop(void) { - char active; - - xSemaphoreTake(mutex, portMAX_DELAY); - active = pcm_active; - pcm_active = 0; - xSemaphoreGive(mutex); - - if (active) i2s_stop(I2S_NUM_0); -} diff --git a/fw/esp32/components/eos/i2c.c b/fw/esp32/components/eos/i2c.c deleted file mode 100644 index 828e4cd..0000000 --- a/fw/esp32/components/eos/i2c.c +++ /dev/null @@ -1,82 +0,0 @@ -#include <stdlib.h> - -#include <esp_log.h> -#include <driver/i2c.h> - -#include "eos.h" - -static const char *TAG = "EOS I2C"; - -#define I2C_MASTER_NUM I2C_NUM_0 -#define I2C_MASTER_FREQ_HZ 100000 -#define I2C_MASTER_GPIO_SCL 25 -#define I2C_MASTER_GPIO_SDA 26 - -#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 ACK_CHECK_EN 0x1 /*!< I2C master will check ack from slave*/ -#define ACK_CHECK_DIS 0x0 /*!< I2C master will not check ack from slave */ -#define ACK_VAL 0x0 /*!< I2C ack value */ -#define NCK_VAL 0x1 /*!< I2C nack value */ - -void eos_i2c_init(void) { - i2c_config_t conf; - conf.mode = I2C_MODE_MASTER; - conf.sda_io_num = I2C_MASTER_GPIO_SDA; - conf.sda_pullup_en = GPIO_PULLUP_ENABLE; - conf.scl_io_num = I2C_MASTER_GPIO_SCL; - conf.scl_pullup_en = GPIO_PULLUP_ENABLE; - conf.master.clk_speed = I2C_MASTER_FREQ_HZ; - i2c_param_config(I2C_MASTER_NUM, &conf); - i2c_driver_install(I2C_MASTER_NUM, conf.mode, I2C_MASTER_RX_BUF_DISABLE, I2C_MASTER_TX_BUF_DISABLE, 0); - ESP_LOGI(TAG, "INIT"); -} - -int eos_i2c_read(uint8_t addr, uint8_t reg, uint8_t *data, size_t len) { - int i, ret; - i2c_cmd_handle_t cmd = i2c_cmd_link_create(); - i2c_master_start(cmd); - i2c_master_write_byte(cmd, addr << 1 | I2C_MASTER_WRITE, ACK_CHECK_EN); - i2c_master_write_byte(cmd, reg, ACK_CHECK_EN); - i2c_master_start(cmd); - i2c_master_write_byte(cmd, addr << 1 | I2C_MASTER_READ, ACK_CHECK_EN); - for (i=0; i < len - 1; i++) { - i2c_master_read_byte(cmd, data+i, ACK_VAL); - } - i2c_master_read_byte(cmd, data+i, NCK_VAL); - i2c_master_stop(cmd); - - ret = i2c_master_cmd_begin(I2C_MASTER_NUM, cmd, 1000 / portTICK_RATE_MS); - i2c_cmd_link_delete(cmd); - if (ret != ESP_OK) { - return EOS_ERR; - } - return EOS_OK; -} - -int eos_i2c_write(uint8_t addr, uint8_t reg, uint8_t *data, size_t len) { - int i, ret; - i2c_cmd_handle_t cmd = i2c_cmd_link_create(); - i2c_master_start(cmd); - i2c_master_write_byte(cmd, addr << 1 | I2C_MASTER_WRITE, ACK_CHECK_EN); - i2c_master_write_byte(cmd, reg, ACK_CHECK_EN); - for (i=0; i < len; i++) { - i2c_master_write_byte(cmd, *(data+i), ACK_CHECK_EN); - } - i2c_master_stop(cmd); - - ret = i2c_master_cmd_begin(I2C_MASTER_NUM, cmd, 1000 / portTICK_RATE_MS); - i2c_cmd_link_delete(cmd); - if (ret != ESP_OK) { - return EOS_ERR; - } - return EOS_OK; -} - -int eos_i2c_read8(uint8_t addr, uint8_t reg, uint8_t *data) { - return eos_i2c_read(addr, reg, data, 1); -} - -int eos_i2c_write8(uint8_t addr, uint8_t reg, uint8_t data) { - return eos_i2c_write(addr, reg, &data, 1); -} diff --git a/fw/esp32/components/eos/include/_net.h b/fw/esp32/components/eos/include/_net.h deleted file mode 100644 index 35b5308..0000000 --- a/fw/esp32/components/eos/include/_net.h +++ /dev/null @@ -1 +0,0 @@ -#include "net.h"
\ No newline at end of file diff --git a/fw/esp32/components/eos/include/i2c.h b/fw/esp32/components/eos/include/i2c.h deleted file mode 100644 index f014141..0000000 --- a/fw/esp32/components/eos/include/i2c.h +++ /dev/null @@ -1,9 +0,0 @@ -#include <sys/types.h> -#include <stdint.h> - -void eos_i2c_init(void); - -int eos_i2c_read(uint8_t addr, uint8_t reg, uint8_t *data, size_t len); -int eos_i2c_write(uint8_t addr, uint8_t reg, uint8_t *data, size_t len); -int eos_i2c_read8(uint8_t addr, uint8_t reg, uint8_t *data); -int eos_i2c_write8(uint8_t addr, uint8_t reg, uint8_t data); diff --git a/fw/fe310/eos/dev/Makefile b/fw/fe310/eos/dev/Makefile index 75f36ab..874e625 100644 --- a/fw/fe310/eos/dev/Makefile +++ b/fw/fe310/eos/dev/Makefile @@ -1,7 +1,8 @@ include ../../common.mk CFLAGS += -I$(bsp_dir)/include -I$(ext_dir)/crypto -obj = flash.o spi.o net.o bq25895.o sdcard.o sdc_crypto.o lcd.o gt911.o ili9806e.o eve.o ov2640.o cam.o egpio.o fxl6408.o apds9151.o tps61052.o +obj = flash.o aon.o pwr.o batt.o hpamp.o egpio.o eve.o lcd.o ctp.o spi.o net.o sdcard.o sdc_crypto.o app.o +subdirs = drv lib = ../../libeos-dev.a @@ -14,7 +15,13 @@ lib = ../../libeos-dev.a all: $(lib) $(lib): $(obj) - $(AR) rcs $@ $(obj) + for i in $(subdirs); do \ + (cd $$i && $(MAKE)) || exit; \ + done + $(AR) rcs $@ $(obj) drv/*.o clean: + for i in $(subdirs); do \ + (cd $$i && $(MAKE) clean) || exit; \ + done rm -f *.o $(lib) diff --git a/fw/fe310/eos/dev/aon.c b/fw/fe310/eos/dev/aon.c new file mode 100644 index 0000000..3d8aaf6 --- /dev/null +++ b/fw/fe310/eos/dev/aon.c @@ -0,0 +1,29 @@ +#include <stdlib.h> +#include <stdint.h> + +#include "eos.h" +#include "soc/aon.h" + +#include "aon.h" + +#ifdef EOS_DEBUG +#include <stdio.h> +#endif + +#define AON_EVE_REG 0 +#define AON_EVE_MASK 0x03 + +void eos_aon_save4eve(uint8_t power_state) { + uint32_t reg; + + power_state &= AON_EVE_MASK; + reg = eos_aon_get_reg(AON_EVE_REG); + reg &= ~AON_EVE_MASK; + reg |= power_state; + + eos_aon_set_reg(0, power_state); +} + +uint8_t eos_aon_load4eve(void) { + return (eos_aon_get_reg(AON_EVE_REG) & AON_EVE_MASK); +} diff --git a/fw/fe310/eos/dev/aon.h b/fw/fe310/eos/dev/aon.h new file mode 100644 index 0000000..22ba84a --- /dev/null +++ b/fw/fe310/eos/dev/aon.h @@ -0,0 +1,4 @@ +#include <stdint.h> + +void eos_aon_save4eve(uint8_t power_state); +uint8_t eos_aon_load4eve(void);
\ No newline at end of file diff --git a/fw/fe310/eos/dev/batt.c b/fw/fe310/eos/dev/batt.c new file mode 100644 index 0000000..6f1eb97 --- /dev/null +++ b/fw/fe310/eos/dev/batt.c @@ -0,0 +1,54 @@ +#include <stdlib.h> +#include <stdint.h> + +#include "eos.h" +#include "soc/pwr.h" + +#include "drv/bq25895.h" + +#ifdef EOS_DEBUG +#include <stdio.h> +#endif + +int eos_batt_init(void) { + uint8_t wakeup_cause; + int rst, rv; +#ifdef EOS_DEBUG + uint8_t data; + int i; +#endif + + rv = EOS_OK; + + wakeup_cause = eos_pwr_wakeup_cause(); + rst = (wakeup_cause == EOS_PWR_WAKE_RST); + if (rst) { + // if (!rv) rv = bq25895_reg_write(0x14, 0x80); // reset + // if (!rv) rv = bq25895_reg_write(0x14, 0x00); + if (!rv) rv = bq25895_reg_write(0x07, 0x8d); // disable watchdog + if (!rv) rv = bq25895_reg_write(0x03, 0x2e); // disable charging, 3.7V minimum output + } + if (rv) return rv; + +#ifdef EOS_DEBUG + printf("BQ25895:\n"); + for (i=0; i<0x15; i++) { + rv = bq25895_reg_read(i, &data); + if (!rv) printf(" REG%.2X: %.2X\n", i, data); + } +#endif + + return EOS_OK; +} + +int eos_batt_read_fault(uint8_t *fault0, uint8_t *fault1) { + int rv; + + rv = bq25895_read_fault(fault0); + if (rv) return rv; + + rv = bq25895_read_fault(fault1); + if (rv) return rv; + + return EOS_OK; +}
\ No newline at end of file diff --git a/fw/fe310/eos/dev/batt.h b/fw/fe310/eos/dev/batt.h new file mode 100644 index 0000000..e761a37 --- /dev/null +++ b/fw/fe310/eos/dev/batt.h @@ -0,0 +1,4 @@ +#include <stdint.h> + +int eos_batt_init(void); +int eos_batt_read_fault(uint8_t *fault0, uint8_t *fault1); diff --git a/fw/fe310/eos/dev/cam.h b/fw/fe310/eos/dev/cam.h new file mode 100644 index 0000000..5153464 --- /dev/null +++ b/fw/fe310/eos/dev/cam.h @@ -0,0 +1,14 @@ +#include "cam_def.h" +#include "drv/ov2640.h" +#include "drv/arducam.h" + +#define eos_cam_init ov2640_init +#define eos_cam_set_pixfmt ov2640_set_pixfmt +#define eos_cam_set_framesize ov2640_set_pixfmt + +#define eos_cam_capture arducam_capture +#define eos_cam_capture_done arducam_capture_done +#define eos_cam_capture_wait arducam_capture_wait +#define eos_cam_fbuf_size arducam_fbuf_size +#define eos_cam_fbuf_read arducam_fbuf_read +#define eos_cam_fbuf_done arducam_fbuf_done diff --git a/fw/fe310/eos/dev/cam_def.h b/fw/fe310/eos/dev/cam_def.h new file mode 100644 index 0000000..4a44f98 --- /dev/null +++ b/fw/fe310/eos/dev/cam_def.h @@ -0,0 +1,65 @@ +typedef enum { + CAM_PIXFORMAT_INVALID = 0, + CAM_PIXFORMAT_BINARY, // 1BPP/BINARY + CAM_PIXFORMAT_GRAYSCALE, // 1BPP/GRAYSCALE + CAM_PIXFORMAT_RGB565, // 2BPP/RGB565 + CAM_PIXFORMAT_YUV422, // 2BPP/YUV422 + CAM_PIXFORMAT_BAYER, // 1BPP/RAW + CAM_PIXFORMAT_JPEG, // JPEG/COMPRESSED +} cam_pixformat_t; + +typedef enum { + CAM_FRAMESIZE_INVALID = 0, + // C/SIF Resolutions + CAM_FRAMESIZE_QQCIF, // 88x72 + CAM_FRAMESIZE_QCIF, // 176x144 + CAM_FRAMESIZE_CIF, // 352x288 + CAM_FRAMESIZE_QQSIF, // 88x60 + CAM_FRAMESIZE_QSIF, // 176x120 + CAM_FRAMESIZE_SIF, // 352x240 + // VGA Resolutions + CAM_FRAMESIZE_QQQQVGA, // 40x30 + CAM_FRAMESIZE_QQQVGA, // 80x60 + CAM_FRAMESIZE_QQVGA, // 160x120 + CAM_FRAMESIZE_QVGA, // 320x240 + CAM_FRAMESIZE_VGA, // 640x480 + CAM_FRAMESIZE_HQQQVGA, // 60x40 + CAM_FRAMESIZE_HQQVGA, // 120x80 + CAM_FRAMESIZE_HQVGA, // 240x160 + // FFT Resolutions + CAM_FRAMESIZE_64X32, // 64x32 + CAM_FRAMESIZE_64X64, // 64x64 + CAM_FRAMESIZE_128X64, // 128x64 + CAM_FRAMESIZE_128X128, // 128x128 + CAM_FRAMESIZE_320X320, // 320x320 + // Other + CAM_FRAMESIZE_LCD, // 128x160 + CAM_FRAMESIZE_QQVGA2, // 128x160 + CAM_FRAMESIZE_WVGA, // 720x480 + CAM_FRAMESIZE_WVGA2, // 752x480 + CAM_FRAMESIZE_SVGA, // 800x600 + CAM_FRAMESIZE_XGA, // 1024x768 + CAM_FRAMESIZE_SXGA, // 1280x1024 + CAM_FRAMESIZE_UXGA, // 1600x1200 + CAM_FRAMESIZE_HD, // 1280x720 + CAM_FRAMESIZE_FHD, // 1920x1080 + CAM_FRAMESIZE_QHD, // 2560x1440 + CAM_FRAMESIZE_QXGA, // 2048x1536 + CAM_FRAMESIZE_WQXGA, // 2560x1600 + CAM_FRAMESIZE_WQXGA2, // 2592x1944 +} cam_framesize_t; + +typedef enum { + CAM_GAINCEILING_2X, + CAM_GAINCEILING_4X, + CAM_GAINCEILING_8X, + CAM_GAINCEILING_16X, + CAM_GAINCEILING_32X, + CAM_GAINCEILING_64X, + CAM_GAINCEILING_128X, +} cam_gainceiling_t; + +typedef enum { + CAM_SDE_NORMAL, + CAM_SDE_NEGATIVE, +} cam_sde_t; diff --git a/fw/fe310/eos/dev/net.c b/fw/fe310/eos/dev/net.c index d340e29..c8b90f3 100644 --- a/fw/fe310/eos/dev/net.c +++ b/fw/fe310/eos/dev/net.c @@ -3,13 +3,12 @@ #include "encoding.h" #include "platform.h" +#include "board.h" #include "eos.h" #include "msgq.h" #include "event.h" -#include "board.h" - #include "soc/interrupt.h" #include "soc/timer.h" #include "soc/pwr.h" @@ -331,7 +330,7 @@ static void net_stop(void) { eos_intr_set_handler(INT_SPI1_BASE, NULL); } -int eos_net_init(uint8_t wakeup_cause) { +int eos_net_init(void) { int i; eos_msgq_init(&net_send_q, net_sndq_array, EOS_NET_SIZE_BUFQ); @@ -364,12 +363,15 @@ int eos_net_init(uint8_t wakeup_cause) { return EOS_OK; } -int eos_net_run(uint8_t wakeup_cause) { +int eos_net_run(void) { + uint8_t wakeup_cause; + net_start(); + wakeup_cause = eos_pwr_wakeup_cause(); clear_csr(mstatus, MSTATUS_MIE); if (wakeup_cause != EOS_PWR_WAKE_RST) { - if (wakeup_cause != EOS_PWR_WAKE_BTN) { + if (wakeup_cause != EOS_PWR_WAKE_PIN) { net_xchg_wake(); } if (!(net_state_flags & NET_STATE_FLAG_CTS)) { @@ -413,9 +415,9 @@ int eos_net_sleep(uint32_t timeout) { if (rv) return rv; - start = eos_time_get_tick(); + start = eos_get_tick(); do { - if (eos_time_delta_ms(start) > timeout) return EOS_ERR_TIMEOUT; + if (eos_tdelta_ms(start) > timeout) return EOS_ERR_TIMEOUT; clear_csr(mstatus, MSTATUS_MIE); eos_evtq_flush_isr(); done = (eos_msgq_len(&net_send_q) == 0); @@ -428,7 +430,7 @@ int eos_net_sleep(uint32_t timeout) { } while (!done); while (!(GPIO_REG(GPIO_RISE_IP) & (1 << NET_PIN_CTS))) { - if (eos_time_delta_ms(start) > timeout) { + if (eos_tdelta_ms(start) > timeout) { rv = EOS_ERR_TIMEOUT; break; } @@ -516,29 +518,28 @@ void eos_net_free(unsigned char *buffer, unsigned char more) { static int net_xchg(unsigned char *type, unsigned char *buffer, uint16_t *len, unsigned char flags) { int rv = EOS_OK; - int _sync = 0; + int sync = 0, dsel = 0; unsigned char _type = *type; uint16_t _len = *len; - uint8_t spi_dev = EOS_SPI_DEV_NET; if (flags & EOS_NET_FLAG_ONEW) _type |= EOS_NET_MTYPE_FLAG_ONEW; if (flags & EOS_NET_FLAG_REPL) _type |= EOS_NET_MTYPE_FLAG_REPL; - if (flags & EOS_NET_FLAG_SYNC) _sync = 1; + if (flags & EOS_NET_FLAG_SYNC) sync = 1; clear_csr(mstatus, MSTATUS_MIE); - if ((flags & EOS_NET_FLAG_ONEW) && !(net_state_flags & NET_STATE_FLAG_RUN)) _sync = 1; - - if (_sync && !(net_state_flags & NET_STATE_FLAG_RUN)) { - int _rv; + if ((flags & EOS_NET_FLAG_ONEW) && !(net_state_flags & NET_STATE_FLAG_RUN)) sync = 1; + if (sync && !(net_state_flags & NET_STATE_FLAG_RUN)) { set_csr(mstatus, MSTATUS_MIE); - spi_dev = eos_spi_dev(); - _rv = eos_spi_deselect(); - if (_rv) return _rv; + + rv = eos_spi_select(EOS_SPI_DEV_NET); + if (rv) return rv; + + dsel = 1; clear_csr(mstatus, MSTATUS_MIE); } - if (_sync) { + if (sync) { net_pause(); net_wait4cts(); if (flags & EOS_NET_FLAG_SYNC) { @@ -566,7 +567,7 @@ static int net_xchg(unsigned char *type, unsigned char *buffer, uint16_t *len, u } set_csr(mstatus, MSTATUS_MIE); - if (spi_dev != EOS_SPI_DEV_NET) eos_spi_select(spi_dev); + if (dsel) eos_spi_deselect(); return rv; } diff --git a/fw/fe310/eos/dev/net.h b/fw/fe310/eos/dev/net.h index 2482a32..ead88b6 100644 --- a/fw/fe310/eos/dev/net.h +++ b/fw/fe310/eos/dev/net.h @@ -1,4 +1,5 @@ #include <stdint.h> + #include "../event.h" /* common */ @@ -6,7 +7,7 @@ #define EOS_NET_SIZE_BUF EOS_NET_MTU #define EOS_NET_MTYPE_SOCK 1 -#define EOS_NET_MTYPE_RNG 3 +#define EOS_NET_MTYPE_RNG 3 #define EOS_NET_MTYPE_POWER 4 #define EOS_NET_MTYPE_WIFI 5 @@ -27,8 +28,8 @@ #define EOS_NET_FLAG_SYNC 0x2 #define EOS_NET_FLAG_REPL 0x4 -int eos_net_init(uint8_t wakeup_cause); -int eos_net_run(uint8_t wakeup_cause); +int eos_net_init(void); +int eos_net_run(void); void eos_net_start(void); void eos_net_stop(void); int eos_net_sleep(uint32_t timeout); diff --git a/fw/fe310/eos/dev/pwr.c b/fw/fe310/eos/dev/pwr.c new file mode 100644 index 0000000..c6537cb --- /dev/null +++ b/fw/fe310/eos/dev/pwr.c @@ -0,0 +1,48 @@ +#include <stdlib.h> +#include <stdint.h> + +#include "eos.h" +#include "soc/pwr.h" +#include "eve/eve.h" +#include "eve/eve_touch_engine.h" + +#include "eve.h" +#include "lcd.h" +#include "ctp.h" +#include "net.h" +#include "flash.h" +#include "aon.h" + +#include "pwr.h" + +#ifdef EOS_DEBUG +#include <stdio.h> +#endif + +void eos_pwr_sys_sleep(void) { + int rv; + + rv = eos_lcd_sleep(); +#ifdef EOS_DEBUG + if (rv) printf("PWR SLEEP: LCD SLEEP ERR:%d\n", rv); +#endif + + rv = eos_ctp_sleep(); +#ifdef EOS_DEBUG + if (rv) printf("PWR SLEEP: CTP SLEEP ERR:%d\n", rv); +#endif + + rv = eos_eve_sleep(); +#ifdef EOS_DEBUG + if (rv) printf("PWR SLEEP: EVE SLEEP ERR:%d\n", rv); +#endif + + rv = eos_net_sleep(1000); +#ifdef EOS_DEBUG + if (rv) printf("PWR SLEEP: NET SLEEP ERR:%d\n", rv); +#endif + + eos_flash_norm(); + + eos_pwr_sleep(); +} diff --git a/fw/fe310/eos/dev/pwr.h b/fw/fe310/eos/dev/pwr.h new file mode 100644 index 0000000..d3125f4 --- /dev/null +++ b/fw/fe310/eos/dev/pwr.h @@ -0,0 +1 @@ +void eos_pwr_sys_sleep(void); diff --git a/fw/fe310/eos/dev/sdc_crypto.c b/fw/fe310/eos/dev/sdc_crypto.c index f0e935d..0cb7a78 100644 --- a/fw/fe310/eos/dev/sdc_crypto.c +++ b/fw/fe310/eos/dev/sdc_crypto.c @@ -9,9 +9,9 @@ #define SDC_CRYPTO_BLK_SIZE 16 #define SDC_CRYPTO_HASH_SIZE 20 -EOSSDCCrypto *sdc_crypto; +static EOSSDCCrypto *sdc_crypto; -void eos_sdcc_init(EOSSDCCrypto *crypto, uint8_t *key, void *ctx, eve_sdcc_init_t init, eve_sdcc_crypt_t enc, eve_sdcc_crypt_t dec, void *ctx_essiv, eve_sdcc_init_t init_essiv, eve_sdcc_essiv_t enc_essiv) { +void eos_sdcc_init(EOSSDCCrypto *crypto, uint8_t *key, void *ctx, eos_sdcc_init_t init, eos_sdcc_crypt_t enc, eos_sdcc_crypt_t dec, void *ctx_essiv, eos_sdcc_init_t init_essiv, eos_sdcc_essiv_t enc_essiv) { char key_essiv[SDC_CRYPTO_HASH_SIZE]; sdc_crypto = crypto; @@ -28,7 +28,7 @@ void eos_sdcc_init(EOSSDCCrypto *crypto, uint8_t *key, void *ctx, eve_sdcc_init_ sdc_crypto->enc_essiv = enc_essiv; } -void eos_sdcc_encrypt(uint32_t sect, uint8_t *buffer) { +void eos_sdc_encrypt(uint32_t sect, uint8_t *buffer) { uint8_t iv[SDC_CRYPTO_BLK_SIZE]; if (sdc_crypto == NULL) return; @@ -39,7 +39,7 @@ void eos_sdcc_encrypt(uint32_t sect, uint8_t *buffer) { sdc_crypto->enc(sdc_crypto->ctx, iv, buffer, 512); } -void eos_sdcc_decrypt(uint32_t sect, uint8_t *buffer) { +void eos_sdc_decrypt(uint32_t sect, uint8_t *buffer) { uint8_t iv[SDC_CRYPTO_BLK_SIZE]; if (sdc_crypto == NULL) return; diff --git a/fw/fe310/eos/dev/sdc_crypto.h b/fw/fe310/eos/dev/sdc_crypto.h index 6442547..176483a 100644 --- a/fw/fe310/eos/dev/sdc_crypto.h +++ b/fw/fe310/eos/dev/sdc_crypto.h @@ -1,18 +1,18 @@ #include <stddef.h> #include <stdint.h> -typedef void (*eve_sdcc_init_t) (void *, uint8_t *); -typedef void (*eve_sdcc_crypt_t) (void *, uint8_t *, uint8_t *, size_t); -typedef void (*eve_sdcc_essiv_t) (void *, uint8_t *); +typedef void (*eos_sdcc_init_t) (void *, uint8_t *); +typedef void (*eos_sdcc_crypt_t) (void *, uint8_t *, uint8_t *, size_t); +typedef void (*eos_sdcc_essiv_t) (void *, uint8_t *); typedef struct EOSSDCCrypto { void *ctx; - eve_sdcc_crypt_t enc; - eve_sdcc_crypt_t dec; + eos_sdcc_crypt_t enc; + eos_sdcc_crypt_t dec; void *ctx_essiv; - eve_sdcc_essiv_t enc_essiv; + eos_sdcc_essiv_t enc_essiv; } EOSSDCCrypto; -void eos_sdcc_init(EOSSDCCrypto *crypto, uint8_t *key, void *ctx, eve_sdcc_init_t init, eve_sdcc_crypt_t enc, eve_sdcc_crypt_t dec, void *ctx_essiv, eve_sdcc_init_t init_essiv, eve_sdcc_essiv_t enc_essiv); -void eos_sdcc_encrypt(uint32_t sect, uint8_t *buffer); -void eos_sdcc_decrypt(uint32_t sect, uint8_t *buffer); +void eos_sdcc_init(EOSSDCCrypto *crypto, uint8_t *key, void *ctx, eos_sdcc_init_t init, eos_sdcc_crypt_t enc, eos_sdcc_crypt_t dec, void *ctx_essiv, eos_sdcc_init_t init_essiv, eos_sdcc_essiv_t enc_essiv); +void eos_sdc_encrypt(uint32_t sect, uint8_t *buffer); +void eos_sdc_decrypt(uint32_t sect, uint8_t *buffer); diff --git a/fw/fe310/eos/dev/sdcard.c b/fw/fe310/eos/dev/sdcard.c new file mode 100644 index 0000000..1edad96 --- /dev/null +++ b/fw/fe310/eos/dev/sdcard.c @@ -0,0 +1,38 @@ +#include <stdlib.h> +#include <stdint.h> + +#include "eos.h" + +#include "board.h" +#include "spi.h" + +#include "drv/sdcard.h" +#include "sdcard.h" + +#ifdef EOS_DEBUG +#include <stdio.h> +#endif + +void eos_sdc_insert(int sdc_det) { + int rv; + + rv = EOS_OK; + if (sdc_det) { + eos_spi_set_div(EOS_SPI_DEV_SDC, 1024); // 100 - 400 kHz + + rv = eos_spi_select(EOS_SPI_DEV_SDC); + if (rv) goto sdc_insert_fin; + + rv = sdc_init(1000); + eos_spi_deselect(); + +sdc_insert_fin: + eos_spi_set_div(EOS_SPI_DEV_SDC, SPI_DIV_SDC); + } else { + sdc_clear(); + } + +#ifdef EOS_DEBUG + if (rv) printf("SDC INSERT ERR:%d\n", rv); +#endif +} diff --git a/fw/fe310/eos/dev/sdcard.h b/fw/fe310/eos/dev/sdcard.h new file mode 100644 index 0000000..cefc304 --- /dev/null +++ b/fw/fe310/eos/dev/sdcard.h @@ -0,0 +1,3 @@ +#include <stdint.h> + +void eos_sdc_insert(int sdc_det); diff --git a/fw/fe310/eos/net/pwr.c b/fw/fe310/eos/net/pwr.c deleted file mode 100644 index 308a05a..0000000 --- a/fw/fe310/eos/net/pwr.c +++ /dev/null @@ -1,80 +0,0 @@ -#include <stdlib.h> -#include <stdint.h> - -#include "eos.h" -#include "event.h" -#include "dev/net.h" - -#include "soc/pwr.h" -#include "soc/spi.h" -#include "dev/spi.h" -#include "dev/net.h" -#include "dev/lcd.h" -#include "eve/eve.h" -#include "dev/flash.h" - -#include "pwr.h" - -static eos_evt_handler_t evt_handler[EOS_PWR_MAX_MTYPE]; -static unsigned char power_btn_down; - -static void pwr_handle_msg(unsigned char type, unsigned char *buffer, uint16_t len) { - unsigned char mtype; - - if ((buffer == NULL) || (len < 1)) { - eos_net_bad_handler(type, buffer, len); - return; - } - - mtype = buffer[0]; - if ((mtype < EOS_PWR_MAX_MTYPE) && evt_handler[mtype]) { - evt_handler[mtype](mtype, buffer, len); - } else { - eos_net_bad_handler(type, buffer, len); - } -} - -static void pwr_handle_btn(unsigned char type, unsigned char *buffer, uint16_t len) { - int rv; - unsigned char level = buffer[1]; - - eos_net_free(buffer, 0); - if (!level) { - power_btn_down = 1; - return; - } - if (!power_btn_down) return; - - rv = eos_lcd_sleep(); - - rv = eos_spi_select(EOS_SPI_DEV_EVE); - if (!rv) { - eve_pwr_sleep(); - eos_spi_deselect(); - } - - rv = eos_net_sleep(1000); - - eos_flash_norm(); - - eos_pwr_sleep(); -} - -void eos_pwr_net_init(void) { - int i; - - for (i=0; i<EOS_PWR_MAX_MTYPE; i++) { - evt_handler[i] = NULL; - } - eos_net_set_handler(EOS_NET_MTYPE_POWER, pwr_handle_msg); - eos_pwr_set_handler(EOS_PWR_MTYPE_BUTTON, pwr_handle_btn); -} - -void eos_pwr_set_handler(unsigned char mtype, eos_evt_handler_t handler) { - if (mtype < EOS_PWR_MAX_MTYPE) evt_handler[mtype] = handler; -} - -eos_evt_handler_t eos_pwr_get_handler(unsigned char mtype) { - if (mtype < EOS_PWR_MAX_MTYPE) return evt_handler[mtype]; - return NULL; -} diff --git a/fw/fe310/eos/net/pwr.h b/fw/fe310/eos/net/pwr.h deleted file mode 100644 index b82a96b..0000000 --- a/fw/fe310/eos/net/pwr.h +++ /dev/null @@ -1,10 +0,0 @@ -#include <stdint.h> -#include "../event.h" - -#define EOS_PWR_MTYPE_BUTTON 1 - -#define EOS_PWR_MAX_MTYPE 2 - -void eos_pwr_net_init(void); -void eos_pwr_set_handler(unsigned char mtype, eos_evt_handler_t handler); -eos_evt_handler_t eos_pwr_get_handler(unsigned char mtype); |