diff options
-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 |
15 files changed, 307 insertions, 38 deletions
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); |