code
stringlengths
1
1.05M
repo_name
stringlengths
6
83
path
stringlengths
3
242
language
stringclasses
222 values
license
stringclasses
20 values
size
int64
1
1.05M
/* * Copyright (C) 2015-2020 Alibaba Group Holding Limited */ #include <stdio.h> #include <stdlib.h> #include <aos/errno.h> #include <aos/kernel.h> #include <k_api.h> #include "aos/hal/pwm.h" #include "aos/cli.h" static int32_t pwm_test_process() { int32_t ret = 0; pwm_dev_t pwm = {0, {0.0, 25}, NULL}; for (int k = 0; k < 1; k++) { pwm.port = k; printf("\r\n=====pwm test : testing...===\r\n"); ret = hal_pwm_init(&pwm); if (ret) { printf("\r\n=====pwm test : pwm init failed===\r\n"); return -1; } ret = hal_pwm_start(&pwm); if (ret) { printf("\r\n=====pwm test : pwm start failed===\r\n"); return -1; } pwm_config_t para = {0.0, 25}; for (int j = 0; j < 2; j++) { for (int i = 0; i < 10; i++) { para.duty_cycle = 0.1 * i; hal_pwm_para_chg(&pwm, para); osDelay(100); } for (int i = 10; i > 0; i--) { para.duty_cycle = 0.01 * i; hal_pwm_para_chg(&pwm, para); osDelay(100); } } hal_pwm_stop(&pwm); hal_pwm_finalize(&pwm); } printf("=====pwm test : Done=====\r\n"); return 0; } static int pwm_autotest() { int32_t ret = 0; printf("\r\n\r\n"); printf("***************************************************************\r\n"); printf("*************************** PWM Test **************************\r\n"); printf("***************************************************************\r\n"); printf("***************************************************************\r\n"); printf("=====pwm test : Start=====\r\n"); ret = pwm_test_process(); if (ret) { printf("\r\n=====pwm test : Failed ===\r\n"); goto fail; } printf("===Result : pwm test PASS !!! ===\r\n"); return 0; fail: printf("===Warning: pwm test FAIL !!! ===\r\n"); return -1; } static void handle_pwmtest_cmd(char *pwbuf, int blen, int argc, char **argv) { pwm_autotest(); } static struct cli_command pwmtest_cmd = { .name = "pwmtest", .help = "pwmtest", .function = handle_pwmtest_cmd }; int pwm_test() { aos_cli_register_command(&pwmtest_cmd); return pwm_autotest(); }
YifuLiu/AliOS-Things
hardware/board/haaseduk1/board_test/pwm_test.c
C
apache-2.0
2,357
/* * Copyright (C) 2015-2020 Alibaba Group Holding Limited */ #include <stdio.h> #include <stdlib.h> #include <aos/errno.h> #include <aos/kernel.h> #include "aos/init.h" #include "board.h" #include <k_api.h> #include "aos/cli.h" #define SDTEST_FILE_NAME "/sdcard/sdtest.test" #define SDTEST_FILE_LEN (1024 * 1024) #define SDTEST_WORDS "sdtest\r\n" static FILE *testfd = NULL; static int sdtest_write(void) { int i = 0; int j = 0; int ret = 0; char *data = NULL; int readbytes = 0; int writebytes = 0; int words_len = strlen(SDTEST_WORDS); printf("\n====sd write test start ... ===\n"); testfd = fopen(SDTEST_FILE_NAME, "w"); if (testfd == NULL) { printf("open /sdcard/test fail !!!\n"); printf("====Result: sd write test FAIL !!!===\n"); return -1; } printf("begin write zero test\n"); data = (char *) malloc(words_len); for (i = 0; i < SDTEST_FILE_LEN / words_len; i++) { memset(data, 0, words_len); writebytes = fwrite(data, 1, words_len, testfd); if (writebytes != words_len) { printf("sdtest write %d bytes to %s failed, return %d\n", words_len, SDTEST_FILE_NAME, writebytes); printf("====Result: sd write test FAIL !!!===\n"); free(data); fclose(testfd); return -1; } } fclose(testfd); free(data); testfd = fopen(SDTEST_FILE_NAME, "r"); if (testfd == NULL) { printf("open /sdcard/test fail !!!\n"); printf("====Result: sd write test FAIL !!!===\n"); return -1; } data = (char *) malloc(SDTEST_FILE_LEN); memset(data, 0, SDTEST_FILE_LEN); readbytes = fread(data, 1, SDTEST_FILE_LEN, testfd); if (readbytes != SDTEST_FILE_LEN) { printf("sdtest read %d bytes form %s failed, return %d\n", SDTEST_FILE_LEN, SDTEST_FILE_NAME, readbytes); printf("====Result: sd write test FAIL !!!===\n"); free(data); fclose(testfd); return -1; } for (i = 0; i < SDTEST_FILE_LEN; i++) { if (data[i] != 0) { printf("sdtest read %d bytes form %s failed, data[%d] %d\n", SDTEST_FILE_LEN, SDTEST_FILE_NAME, i, (int)data[i]); printf("====Result: sd write test FAIL !!!===\n"); free(data); fclose(testfd); return -1; } } fclose(testfd); testfd = fopen(SDTEST_FILE_NAME, "w"); if (testfd == NULL) { printf("open /sdcard/test fail !!!\n"); printf("====Result: sd write test FAIL !!!===\n"); free(data); return -1; } for (i = 0; i < SDTEST_FILE_LEN / strlen(SDTEST_WORDS); i++) { memcpy(data + i * strlen(SDTEST_WORDS), SDTEST_WORDS, strlen(SDTEST_WORDS)); } printf("begin write data test\n"); writebytes = fwrite(data, 1, SDTEST_FILE_LEN, testfd); if (writebytes != SDTEST_FILE_LEN) { printf("write data SDTEST_FILE_LEN bytes to file /sdcard/test fail !!!\n"); printf("====Result: sd write test FAIL !!!===\n"); free(data); fclose(testfd); return -1; } printf("====Result: sd write test PASS !!!===\n"); free(data); fclose(testfd); return 0; } static int sdtest_read(void) { int i = 0; int j = 0; int ret = 0; char *data = NULL; int readbytes = 0; int words_len = strlen(SDTEST_WORDS); printf("\r\n====sd read test start ... ===\n"); testfd = fopen(SDTEST_FILE_NAME, "r"); if (testfd == NULL) { printf("open /sdcard/test fail !!!\n"); printf("====Result: sd read test FAIL !!!===\n"); return -1; } data = (char *) malloc(words_len); for (i = 0; i < SDTEST_FILE_LEN / words_len; i++) { memset(data, 0, words_len); readbytes = fread(data, 1, words_len, testfd); if (readbytes != words_len) { printf("sdtest read %d bytes form %s failed, return %d\n", words_len, SDTEST_FILE_NAME, readbytes); ret = -1; goto test_err; } if (0 != strncmp(data, SDTEST_WORDS, words_len)) { printf("sdtest read %d bytes form %s, data error\n", words_len, SDTEST_FILE_NAME); printf("read "); for (j = 0; j < words_len; j++) { printf("0x%x", (uint32_t)data[j]); } printf(", "); printf("actual %s\n", SDTEST_WORDS); ret = -1; goto test_err; } } printf("====Result: sd read test PASS !!!===\n"); test_err: free(data); fclose(testfd); if (ret != 0) { printf("====Result: sd read test FAIL !!!===\n\n"); } return ret; } static void handle_sdtest_cmd(char *pwbuf, int blen, int argc, char **argv) { if (argc < 2) { printf("Usage: sdtest read/write\n"); return; } if (strcmp(argv[1], "read") == 0) { sdtest_read(); } else if (strcmp(argv[1], "write") == 0) { sdtest_write(); } else { printf("Usage: sdtest read/write\n"); return; } } static struct cli_command sdtest_cmd = { .name = "sdtest", .help = "sdtest [read/write]", .function = handle_sdtest_cmd }; int sdcard_test(void) { int i = 0; int ret = 0; char *data = NULL; printf("\r\n\r\n"); printf("***************************************************************\r\n"); printf("*********************** sdcard Test ***************************\r\n"); printf("** How to test: pls format sdcard and insert it to socket *****\r\n"); printf("***************************************************************\r\n"); printf("=====sdcard test : Start=====\r\n"); aos_cli_register_command(&sdtest_cmd); aos_unlink(SDTEST_FILE_NAME); aos_rmdir(SDTEST_FILE_NAME); testfd = fopen(SDTEST_FILE_NAME, "w"); if (testfd == NULL) { printf("create /sdcard/sdtest.test fail !!!\n"); return; } printf("create /sdcard/sdtest.test success !!!\n"); data = (char *)malloc(SDTEST_FILE_LEN); for (i = 0; i < SDTEST_FILE_LEN / strlen(SDTEST_WORDS); i++) { memcpy(data + i * strlen(SDTEST_WORDS), SDTEST_WORDS, strlen(SDTEST_WORDS)); } printf("begin init /sdcard/sdtest.test ...\n"); ret = fwrite(data, 1, SDTEST_FILE_LEN, testfd); if (ret != SDTEST_FILE_LEN) { printf("write data SDTEST_FILE_LEN bytes to file /sdcard/sdtest.test fail !!!\n"); } fsync(testfd); printf("write init data to /sdcard/sdtest.test success !!!\n"); fclose(testfd); free(data); aos_msleep(1000); ret = sdtest_read(); ret += sdtest_write(); aos_unlink(SDTEST_FILE_NAME); return ret; }
YifuLiu/AliOS-Things
hardware/board/haaseduk1/board_test/sd_test.c
C
apache-2.0
6,727
/* * Copyright (C) 2015-2020 Alibaba Group Holding Limited */ #include <stdio.h> #include <stdlib.h> #include <aos/errno.h> #include <aos/kernel.h> #include "aos/init.h" #include "board.h" #include <k_api.h> #include "aos/cli.h" #include "ulog/ulog.h" #include "led.h" #include "key.h" #include "hal_oled.h" #include "drv_temp_humi_si_si7006.h" #include "drv_temp_humi_sensylink_cht8305.h" #include "drv_acc_gyro_inv_mpu6050.h" #include "drv_acc_gyro_qst_qmi8610.h" #include "drv_baro_goertek_spl06.h" #include "drv_baro_qst_qmp6988.h" #include "drv_mag_qst_qmc5883l.h" #include "drv_mag_qst_qmc6310.h" #include "drv_als_ps_ir_liteon_ap3216c.h" typedef int (*sensortest_cb)(int turn); static int sensors_test_inited = 0; static int humiture_test(uint8_t turn); static int gyro_test(uint8_t turn); static int mag_test(uint8_t turn); static int baro_test(uint8_t turn); static int ap3216c_test(uint8_t turn); static int g_haasboard_is_k1c = 0; sensortest_cb sensor_test_funs[] = { humiture_test, gyro_test, mag_test, baro_test, ap3216c_test, }; extern int usb_class_detect; static int humiture_test(uint8_t turn) { printf("\r\n\r\n"); printf("***************************************************************\r\n"); printf("******************* Sensor HUMITURE Test **********************\r\n"); printf("** How to test: ***********************************************\r\n"); printf("***************************************************************\r\n"); printf("***************************************************************\r\n"); printf("\r\n === test start====\r\n"); uint8_t id_buf[8] = {0}; float Temp = 0.0, Humidity = 0.0; LOGI("SENSOR_HUMI_TEST", "test start, turn %d\n", turn); if (g_haasboard_is_k1c) { cht8305_init(); } else { si7006_init(); } aos_msleep(200); while (turn--) { if (g_haasboard_is_k1c) { cht8305_getTempHumidity(&Humidity, &Temp); LOGI("humiture_test", "Temp :%f Humidity : %f\n", Temp, Humidity); if ((Humidity > 300.0 || Humidity < -100.0) || (Temp > 200.0 || Temp < -50.0)) { cht8305_deinit(); goto _failed; } printf("===Result : SENSOR HUMI TEST PASS !!! ===\r\n"); cht8305_deinit(); return 0; } else { // get data si7006_getTempHumidity(&Humidity, &Temp); LOGI("humiture_test", "Temp :%f Humidity : %f\n", Temp, Humidity); if ((Humidity > 300.0 || Humidity < -100.0) || (Temp > 200.0 || Temp < -50.0)) { si7006_deinit(); goto _failed; } printf("===Result : SENSOR HUMI TEST PASS !!! ===\r\n"); si7006_deinit(); return 0; } } _failed: printf("===Result: SENSOR HUMI TEST FAIL !!! ===\r\n"); return -1; } static int gyro_test(uint8_t turn) { printf("\r\n\r\n"); printf("***************************************************************\r\n"); printf("************************ GYRO Test ****************************\r\n"); printf("** How to test: ***********************************************\r\n"); printf("***************************************************************\r\n"); printf("***************************************************************\r\n"); printf("\r\n ===GYRO test start====\r\n"); short gx = 0, gy = 0, gz = 0; short ax = 0, ay = 0, az = 0; float acc[3]; LOGI("GYRO_TEST", "test start, turn %d\n", turn); if (g_haasboard_is_k1c) { FisImu_init(); LOGI("GYRO_TEST", "FisImu_init done\n"); } else { MPU_Init(); LOGI("GYRO_TEST", "MPU_Init done\n"); } aos_msleep(200); while (turn--) { if (g_haasboard_is_k1c) { FisImu_read_acc_xyz(acc); if (acc[0] > 4000.0 || acc[0] < -4000.0) { printf("===Result: GYRO test FAIL !!! ===\r\n"); FisImu_deinit(); return -1; } FisImu_deinit(); } else { float temp = MPU_Get_Temperature(); MPU_Deinit(); LOGI("GYRO_TEST", "temp %0.1f\n", temp); if (temp / 100 > 200.0 || temp / 100 < -50.0) { printf("===Result: GYRO test FAIL !!! ===\r\n"); return -1; } } } printf("===Result : GYRO test PASS !!! ===\r\n"); return 0; } static int baro_test(uint8_t turn) { printf("\r\n\r\n"); printf("***************************************************************\r\n"); printf("*********************** BARO Test ****************************\r\n"); printf("** How to test: ***********************************************\r\n"); printf("***************************************************************\r\n"); printf("***************************************************************\r\n"); printf("\r\n ===BARAO test start====\r\n"); spl06_data_t spl06_data = {0}; qmp6988_data p_qmp6988_data = {0}; LOGI("BARO_TEST", "test start, turn %d\n", turn); if (g_haasboard_is_k1c) { p_qmp6988_data.slave = QMP6988_SLAVE_ADDRESS_H; qmp6988_init(&p_qmp6988_data); LOGI("BARO_TEST", "qmp6988_init done\n"); } else { spl06_init(); LOGI("BARO_TEST", "spl06_init done\n"); } aos_msleep(200); while (turn--) { if (g_haasboard_is_k1c) { qmp6988_calc_pressure(&p_qmp6988_data); printf("Temperature: C %0.1f\n", p_qmp6988_data.temperature); printf("Temperature: F %0.1f\n", ((p_qmp6988_data.temperature * 9 / 5) + 32)); printf("Measured Air Pressure: : %0.2f mb\n", p_qmp6988_data.pressure); printf("altitude: %0.2f m\n", p_qmp6988_data.altitude); if (p_qmp6988_data.pressure / 100.0 > 3000.0 || p_qmp6988_data.pressure / 100.0 < 500.0) { printf("===Result: BARO_TEST test FAIL !!! ===\r\n"); qmp6988_deinit(); return -1; } qmp6988_deinit(); } else { spl06_getdata(&spl06_data); printf("Temperature: C %0.1f\n", spl06_data.Ctemp); printf("Temperature: F %0.1f\n", spl06_data.Ftemp); printf("Measured Air Pressure: : %0.2f mb\n", spl06_data.pressure); printf("altitude: %0.2f m\n", spl06_data.altitude); // printf("altitude: %0.2f ft\n", spl06_data.altitude * 3.281); if (spl06_data.pressure > 3000.0 || spl06_data.pressure < 500.0) { printf("===Result: BARO_TEST test FAIL !!! ===\r\n"); spl06_deinit(); return -1; } spl06_deinit(); } } printf("===Result : BARO_TEST test PASS !!! ===\r\n"); return 0; } static int mag_test(uint8_t turn) { printf("\r\n\r\n"); printf("***************************************************************\r\n"); printf("*********************** MAG Test **************************\r\n"); printf("** How to test: ***********************************************\r\n"); printf("***************************************************************\r\n"); printf("***************************************************************\r\n"); printf("\r\n ===MAG test start====\r\n"); LOGI("MAG_TEST", "test start, turn %d\n", turn); int heading = 0; int times = 50; if (g_haasboard_is_k1c) { qmc6310_init(); LOGI("MAG_TEST", "qmc6310_init done\n"); } else { qmc5883l_init(); LOGI("MAG_TEST", "qmc5883l_init done\n"); } while (turn--) { if (g_haasboard_is_k1c) { while(times --){ heading = qmc6310_readHeading(); } heading /= 50; qmc6310_deinit(); LOGD("MAG_TEST", "heading %d\n", heading); } else { while(times --){ heading += qmc5883l_readHeading(); } heading /= 50; qmc5883l_deinit(); LOGD("MAG_TEST", "heading %d\n", heading); } if (heading == 0) { printf("===Result : MAG test FAILs !!! ===\r\n"); return -1; } } printf("===Result: MAG test PASS !!! ===\r\n"); return 0; } static int ap3216c_test(uint8_t turn) { printf("\r\n\r\n"); printf("***************************************************************\r\n"); printf("*********************** AP3216C Test ***************************\r\n"); printf("** How to test: ***********************************************\r\n"); printf("***************************************************************\r\n"); printf("***************************************************************\r\n"); printf("\r\n ===ap3216c test start====\r\n"); LOGI("AP3216C_TEST", "test start, turn %d\n", turn); uint16_t ALS; uint16_t PS = 0, IR = 0; ap3216c_init(); while (turn--) { ALS = ap3216c_read_ambient_light(); PS = ap3216c_read_ps_data(); IR = ap3216c_read_ir_data(); ap3216c_deinit(); if ((PS >> 15) & 1) printf("物体接近\n"); else printf("物体远离\n"); LOGI("APP", "\n光照强度是:%d\n红外强度是:%d\n", ALS, IR); if (ALS <= 0) { printf("===Result : ap3216c test FAIL !!! ===\r\n"); return -1; } } printf("===Result : ap3216c test PASS !!! ===\r\n"); return 0; } static void handle_sensortest_cmd(char *pwbuf, int blen, int argc, char **argv) { if (argv != 2) return; sensortest_cb fun = sensor_test_funs[atoi(argv[0])]; (fun)(atoi(argv[0])); } static struct cli_command sensortest_cmd = { .name = "sensortest", .help = "sensortest", .function = handle_sensortest_cmd }; int sensors_test(int index) { if (!sensors_test_inited) { g_haasboard_is_k1c = haasedu_is_k1c(); aos_cli_register_command(&sensortest_cmd); sensors_test_inited = 1; } if ((index < 0) || (index > 4)) { printf("invalid index %d\n", index); return -1; } return (sensor_test_funs[index])(1); }
YifuLiu/AliOS-Things
hardware/board/haaseduk1/board_test/sensors_test.c
C
apache-2.0
10,319
/* * Copyright (C) 2015-2020 Alibaba Group Holding Limited */ #include <stdio.h> #include <stdlib.h> #include <aos/errno.h> #include <aos/kernel.h> #include <k_api.h> #include "aos/hal/uart.h" #include "aos/cli.h" #define TEST_DATA "hello" static int32_t uart_test_common(uint8_t port, uint32_t baud) { int32_t ret = 0; int32_t i = 0; static int32_t init_flag[3] = {0}; uint32_t recv_size = 0; uint8_t recv_data[10] = {0}; uart_dev_t uart_ttl = {0}; uart_ttl.port = port; /*ttl use uart 2*/ uart_ttl.config.baud_rate = baud; uart_ttl.config.data_width = DATA_WIDTH_8BIT; uart_ttl.config.flow_control = FLOW_CONTROL_DISABLED; uart_ttl.config.mode = MODE_TX_RX; uart_ttl.config.parity = NO_PARITY; uart_ttl.config.stop_bits = STOP_BITS_1; printf("\r\n ====start uart %d test baudrate %d ====\r\n", port, baud); if (port >= 3) { printf("\r\n ======= Invalid uart part %d =====\r\n", port); } if (init_flag[port] == 0) { ret = hal_uart_init(&uart_ttl); hal_uart_finalize(&uart_ttl); ret |= hal_uart_init(&uart_ttl); init_flag[port] = 1; } if (ret) { printf("=====uart test : uart %d dev init fail =====\r\n", port); return -1; } for (i = 0; i < 3; i++) { ret = hal_uart_send(&uart_ttl, TEST_DATA, strlen(TEST_DATA), 1000); if (ret) { printf("=====uart test : uart %d fail to send test data=====\r\n", port); continue; } memset(recv_data, 0, sizeof(recv_data)); aos_msleep(1000); ret = hal_uart_recv_II(&uart_ttl, recv_data, strlen(TEST_DATA), &recv_size, 2000); if (ret || recv_size != strlen(TEST_DATA)) { printf("=====uart test : uart %d fail to recv test data, %d %d, %s =====\r\n", port, ret, recv_size, recv_data); continue; } printf("=====uart test : uart %d send test data is %s recv data is %s =====\r\n", port, TEST_DATA, recv_data); aos_msleep(100); if (strcmp(recv_data, TEST_DATA) == 0) { break; } } if (i >= 3) { printf("=====uart test : uart %d test fail =====\r\n", uart_ttl.port); return -1; } printf("=====uart test : uart %d test successed =====\r\n", uart_ttl.port); return 0; } int uart_ttl_test_internal() { int32_t ret = 0; printf("\r\n\r\n"); printf("***************************************************************\r\n"); printf("************************* UART TTL Test ***********************\r\n"); printf("***************************************************************\r\n"); printf("********* How to test: connect PIN10 and PIN12 ****************\r\n"); printf("***************************************************************\r\n"); printf("=====UART TTL test : Start=====\r\n"); ret = uart_test_common(2, 115200); if (ret) { printf("\r\n=====uart test : ttl test fail ===\r\n"); return -1; } printf("\r\n=====uart test : ttl test successed ===\r\n"); return 0; } void uart_232_test_internal() { int32_t ret = 0; printf("\r\n=====uart test : begin 232 test ===\r\n"); ret = uart_test_common(0, 115200); if (ret) { printf("\r\n=====uart test : 232 test fail ===\r\n"); return ; } printf("\r\n=====uart test : 232 test successed ===\r\n"); } static void handle_uarttest_cmd(char *pwbuf, int blen, int argc, char **argv) { if (argc < 2) { printf("Usage: uarttest ttl/232\n"); return; } if (strcmp(argv[1], "ttl") == 0) { uart_ttl_test_internal(); } else if (strcmp(argv[1], "232") == 0) { uart_232_test_internal(); } else { printf("Usage: uarttest ttl/232\n"); return; } } static struct cli_command uarttest_cmd = { .name = "uarttest", .help = "uarttest [ttl/232]", .function = handle_uarttest_cmd }; int uart_ttl_test() { aos_cli_register_command(&uarttest_cmd); return uart_ttl_test_internal(); } void uart_232_test() { uart_232_test_internal(); }
YifuLiu/AliOS-Things
hardware/board/haaseduk1/board_test/uart_test.c
C
apache-2.0
4,151
/* * Copyright (C) 2015-2020 Alibaba Group Holding Limited */ #include <stdio.h> #include <stdlib.h> #include <aos/errno.h> #include <aos/kernel.h> #include "aos/init.h" #include "board.h" #include <k_api.h> #include "aos/cli.h" extern int usb_class_detect; static int usb_test_internal() { printf("\r\n\r\n"); printf("***************************************************************\r\n"); printf("*********************** USB Test ******************************\r\n"); printf("** How to test: ***********************************************\r\n"); printf("***************************************************************\r\n"); printf("***************************************************************\r\n"); printf("\r\n ===usb test start====\r\n"); /* usb_class_detect = 1; if (usb_class_detect > 0) { printf("===Result : usb test PASS !!! ===\r\n"); return 0; } else { printf("===Warning: usb test FAIL !!! ===\r\n"); return -1; } */ return 0; } static void handle_usbtest_cmd(char *pwbuf, int blen, int argc, char **argv) { usb_test_internal(); } static struct cli_command usbtest_cmd = { .name = "usbtest", .help = "usbtest", .function = handle_usbtest_cmd }; int usb_test(void) { aos_cli_register_command(&usbtest_cmd); return usb_test_internal(); }
YifuLiu/AliOS-Things
hardware/board/haaseduk1/board_test/usb_test.c
C
apache-2.0
1,373
/* * Copyright (C) 2015-2020 Alibaba Group Holding Limited */ #include <stdio.h> #include <stdlib.h> #include <aos/errno.h> #include <aos/kernel.h> #include "aos/init.h" #include "board.h" #include <k_api.h> #include "aos/cli.h" #include "led.h" #include "hal_gpio.h" #include "hal_iomux_haas1000.h" static void timer1_func(void *timer, void *arg) { static int times = 1; printf("\r\n%.1f s\r\n", times * 0.2); times++; } static void handle_watchdog_test_cmd(char *pwbuf, int blen, int argc, char **argv) { aos_timer_t timer1; int status; if (argc < 2) { printf("Usage: watchdog stopfeed\n"); printf("Example: watchdog stopfeed\n"); return; } if (0 == strcmp(argv[1], "stopfeed")) { printf("begin stop feed dog, board will reboot in 1.6 s ...\n"); status = aos_timer_new(&timer1, timer1_func, NULL, 200, 1); if (status != 0) { printf("create timer error\n"); return; } watchdog_stopfeed(); } else { printf("Usage: watchdog stopfeed\n"); printf("Example: watchdog stopfeed\n"); return; } } static struct cli_command watchdog_test_cmd = { .name = "watchdog", .help = "watchdog [stopfeed]", .function = handle_watchdog_test_cmd }; void watchdog_test() { int ret = 0; printf("\r\n\r\n"); printf("***************************************************************\r\n"); printf("*********************** watchdog Test *************************\r\n"); printf("** How to test: input [watchdog stopfeed] command *************\r\n"); printf("***************************************************************\r\n"); printf("=====watchdog test : Start=====\r\n"); aos_cli_register_command(&watchdog_test_cmd); watchdog_stopfeed(); }
YifuLiu/AliOS-Things
hardware/board/haaseduk1/board_test/watchdog_test.c
C
apache-2.0
1,834
#include "board.h" #include "aos/hal/uart.h" #include "aos/hal/i2c.h" #include "cmsis.h" #include "cmsis_os.h" #include "hal_gpio.h" #include "hal_timer.h" #include "hal_trace.h" #include <k_api.h> #if (RHINO_CONFIG_HW_COUNT > 0) #include "haas1000.h" #endif #define SYSTICK_USE_FASTTIMER uart_dev_t uart_0; uint8_t g_haasedu_boardname = HAAS_EDU_K1C; extern void haas_wifi_init(); #if (RHINO_CONFIG_HW_COUNT > 0) void soc_hw_timer_init(void) { /* Enable DWT */ CoreDebug->DEMCR |= ((1 << CoreDebug_DEMCR_TRCENA_Pos)); DWT->CYCCNT = 0; /* Enable CPU cycle counter */ DWT->CTRL |= ((1 << DWT_CTRL_CYCCNTENA_Pos)); } hr_timer_t soc_hr_hw_cnt_get(void) { return DWT->CYCCNT; } uint64_t soc_hr_hw_freq_get(void) { return hal_sys_timer_calc_cpu_freq(5, 0); } lr_timer_t soc_lr_hw_cnt_get(void) { return (lr_timer_t)hal_sys_timer_get(); } float soc_hr_hw_freq_mhz(void) { return hal_sys_timer_calc_cpu_freq(5, 0) / 1000000; } #endif /* RHINO_CONFIG_HW_COUNT */ #if (RHINO_CONFIG_INTRPT_STACK_OVF_CHECK > 0) void soc_intrpt_stack_ovf_check(void) {} #endif #if (RHINO_CONFIG_DYNTICKLESS > 0) void soc_tick_interrupt_set(tick_t next_ticks, tick_t elapsed_ticks) {} tick_t soc_elapsed_ticks_get(void) { return 0; } #endif #if (RHINO_CONFIG_KOBJ_DYN_ALLOC > 0) #define RHINO_HEAP_BLK_SIZE (0x680000) __SRAM_EXT_BSS uint32_t heap_blk0[RHINO_HEAP_BLK_SIZE / sizeof(uint32_t)] = {0}; // __SRAM_EXT_BSS uint32_t heap_blk1[RHINO_HEAP_BLK_SIZE/sizeof(uint32_t)] = {0}; k_mm_region_t g_mm_region[] = { {(uint8_t *)heap_blk0, RHINO_HEAP_BLK_SIZE} // {(uint8_t *)heap_blk1, RHINO_HEAP_BLK_SIZE} }; int g_region_num = sizeof(g_mm_region) / sizeof(k_mm_region_t); void soc_sys_mem_init(void) {} #endif void soc_err_proc(kstat_t err) {} krhino_err_proc_t g_err_proc = soc_err_proc; #define OS_CLOCK OS_CLOCK_NOMINAL #define SYS_TICK_LOAD \ ((uint32_t)((((float)OS_CLOCK * (float)RHINO_CONFIG_TICKS_PER_SECOND)) / \ (float)1E6 + \ 0.5f)) __STATIC_INLINE uint32_t SysTick_Config_Alt(uint32_t ticks) { if ((ticks - 1UL) > SysTick_LOAD_RELOAD_Msk) { return (1UL); /* Reload value impossible */ } SysTick->LOAD = (uint32_t)(ticks - 1UL); /* set reload register */ NVIC_SetPriority(SysTick_IRQn, (1UL << __NVIC_PRIO_BITS) - 1UL); /* set Priority for Systick Interrupt */ SysTick->VAL = 0UL; /* Load the SysTick Counter Value */ SysTick->CTRL = SysTick_CTRL_TICKINT_Msk | SysTick_CTRL_ENABLE_Msk; /* Enable SysTick IRQ and SysTick Timer */ return (0UL); /* Function successful */ } void SysTick_Handler(void) { krhino_intrpt_enter(); krhino_tick_proc(); krhino_intrpt_exit(); } void soc_systick_init(void) { #ifdef SYSTICK_USE_FASTTIMER hal_systick_timer_open(RHINO_CONFIG_TICKS_PER_SECOND, SysTick_Handler); #else SysTick_Config_Alt(SYS_TICK_LOAD); #endif } void soc_systick_start(void) { #ifdef SYSTICK_USE_FASTTIMER hal_systick_timer_start(); #else SysTick->CTRL |= SysTick_CTRL_ENABLE_Msk; #endif } void soc_systick_stop(void) { #ifdef SYSTICK_USE_FASTTIMER hal_systick_timer_stop(); #else SysTick->CTRL &= ~SysTick_CTRL_ENABLE_Msk; #endif } void board_stduart_init() { uart_0.port = 0; uart_0.config.baud_rate = 1500000; uart_0.config.data_width = DATA_WIDTH_8BIT; uart_0.config.flow_control = FLOW_CONTROL_DISABLED; uart_0.config.mode = MODE_TX_RX; uart_0.config.parity = NO_PARITY; uart_0.config.stop_bits = STOP_BITS_1; hal_uart_init(&uart_0); } int haasedu_is_k1c() { int value = 0; int len = 4; if (0 == aos_kv_get("HAASEDU_NAME", &value, &len)) { printf("HAASEDU_NAME is %d\r\n", value); if (value == 1) { printf("3333 is %d\r\n", value); return 1; } else { return 0; } } else { printf("HAASEDU_NAME is avild %d!\r\n", value); return 0; } } void board_detect() { int re_value = 0; int len = 4; uint8_t chip_id = 0x00; int32_t ret = sensor_i2c_open(1, 0x6b, I2C_BUS_BIT_RATES_100K, 0); if (ret) { printf("sensor i2c open failed, ret:%d\n", ret); return; } FisImu_read_reg(0, &chip_id, 1); aos_msleep(100); ret = sensor_i2c_close(1); if (ret) { printf("sensor i2c close failed, ret:%d\n", ret); return; } if (chip_id == 0xfc) { g_haasedu_boardname = HAAS_EDU_K1C; re_value = 1; aos_kv_set("HAASEDU_NAME", &re_value, len, 1); printf("haasedu name is K1C\n"); } else { g_haasedu_boardname = HAAS_EDU_K1; re_value = 0; aos_kv_set("HAASEDU_NAME", &re_value, len, 1); printf("haasedu name is K1\n"); } printf("haasedu detected is %d\n", g_haasedu_boardname); return; } void board_dma_init() {} void board_gpio_init() {} void board_tick_init() {} void board_kinit_init() {} void board_flash_init() {} void board_network_init() { haas_wifi_init(); }
YifuLiu/AliOS-Things
hardware/board/haaseduk1/config/board.c
C
apache-2.0
5,242
#ifndef BOARD_H #define BOARD_H #if (CONFIG_A7_DSP_ENABLE == 1) #define DEBUG_LASTWORD_RAM_ADDR 0x20166000 #else #define DEBUG_LASTWORD_RAM_ADDR 0x201e6000 #endif typedef enum { HAAS_EDU_K1 = 0, /**< Playback stream */ HAAS_EDU_K1C, /**< Capture stream */ HAAS_EDU_MAX } haasedu_board_t; extern int haasedu_is_k1c(); void soc_systick_start(void); void soc_systick_stop(void); #endif /* BOARD_H */
YifuLiu/AliOS-Things
hardware/board/haaseduk1/config/board.h
C
apache-2.0
457
/* * Copyright (C) 2015-2017 Alibaba Group Holding Limited */ #include "board.h" #include "hal_gpio.h" #include "hal_sleep.h" #include "hal_timer.h" #include "hal_trace.h" #include "hwtimer_list.h" #include "watchdog.h" #include <k_api.h> #ifdef AOS_COMP_OSAL_POSIX #include "posix/pthread.h" extern pthread_key_list_t pthread_key_list_head; #endif #if RHINO_CONFIG_USER_HOOK extern const k_mm_region_t g_mm_region[]; extern int g_region_num; static int mem_in_heap(uint32_t addr) { int i; for (i = 0; i < g_region_num; i++) { if (addr > (uint32_t)g_mm_region[i].start && addr < (uint32_t)g_mm_region[i].start + g_mm_region[i].len) { return 1; } } return 0; } void krhino_tick_hook(void) { static unsigned int idx = 0; if ((idx % (RHINO_CONFIG_TICKS_PER_SECOND / 2)) == 0) { watchdog_feeddog(); } idx++; } HWTIMER_ID krhino_sleep_timer; void krhino_sleep(void) { hal_sleep_enter_sleep(); } static int idle_sleep = 1; // swd will set it void krhino_idle_hook_onoff(int onoff) { idle_sleep = onoff; } void krhino_idle_hook(void) { uint32_t suspend_time; enum E_HWTIMER_T ret; uint32_t sleep_ms; if (idle_sleep == 0) return; if ((hal_sleep_light_sleep() == HAL_SLEEP_STATUS_DEEP)) { tick_t tick = krhino_next_sleep_ticks_get(); sleep_ms = krhino_ticks_to_ms(tick); if (sleep_ms > 60 * 1000) sleep_ms = 60 * 1000; ret = hwtimer_start(krhino_sleep_timer, MS_TO_HWTICKS(sleep_ms)); if (ret == E_HWTIMER_OK) { soc_systick_stop(); suspend_time = hal_sys_timer_get(); krhino_sleep(); hwtimer_stop(krhino_sleep_timer); suspend_time = TICKS_TO_MS(hal_sys_timer_get() - suspend_time); soc_systick_start(); tick_list_update(krhino_ms_to_ticks(suspend_time)); } } } void aos_trace_crash_notify() { abort(); } void krhino_idle_pre_hook(void) { hal_trace_crash_dump_register(HAL_TRACE_CRASH_DUMP_MODULE_SYS, aos_trace_crash_notify); krhino_sleep_timer = hwtimer_alloc(NULL, NULL); ASSERT(krhino_sleep_timer, "IdleTask: Failed to alloc sleep timer"); } void krhino_start_hook(void) {} void krhino_task_create_hook(ktask_t *task) {} void krhino_task_del_hook(ktask_t *task, res_free_t *arg) { /*free task->task_sem_obj*/ void *task_sem = task->task_sem_obj; g_sched_lock[cpu_cur_get()]++; if (task_sem) { krhino_task_sem_del(task); if (mem_in_heap((uint32_t)task_sem)) { aos_free(task_sem); } task->task_sem_obj = NULL; } g_sched_lock[cpu_cur_get()]--; #ifdef AOS_COMP_OSAL_POSIX _pthread_tcb_t *ptcb; _pthread_cleanup_t *cleanup; pthread_key_list_t *pthread_key_list_s_c = NULL; g_sched_lock[cpu_cur_get()]++; ptcb = _pthread_get_tcb(task); if (ptcb == NULL) { g_sched_lock[cpu_cur_get()]--; return; } if (task->task_name != NULL) { aos_free(task->task_name); task->task_name = NULL; } /* excute all cleanup function if existed */ do { cleanup = ptcb->cleanup; if (cleanup != NULL) { ptcb->cleanup = cleanup->prev; cleanup->cleanup_routine(cleanup->para); aos_free(cleanup); } } while (ptcb->cleanup != NULL); /* call the destructor function of TSD */ pthread_key_list_s_c = &pthread_key_list_head; while (pthread_key_list_s_c != NULL) { if (pthread_key_list_s_c->head.fun != NULL) { pthread_key_list_s_c->head.fun(NULL); } pthread_key_list_s_c = pthread_key_list_s_c->next; } if (ptcb->attr.detachstate == PTHREAD_CREATE_JOINABLE) { /* give join sem if is joinable */ if (ptcb->join_sem != NULL) { krhino_sem_give(ptcb->join_sem); } } if (arg == NULL) { g_sched_lock[cpu_cur_get()]--; return; } if (ptcb->attr.detachstate == PTHREAD_CREATE_DETACHED) { if (ptcb->join_sem != NULL) { krhino_sem_dyn_del(ptcb->join_sem); } klist_insert(&g_res_list, &arg->res_list); arg->res[0] = task->task_stack_base; arg->res[1] = task; arg->res[2] = ptcb; arg->cnt += 3; krhino_sem_give(&g_res_sem); } g_sched_lock[cpu_cur_get()]--; #endif return; } void krhino_init_hook(void) {} void krhino_task_switch_hook(ktask_t *orgin, ktask_t *dest) {} void krhino_mm_alloc_hook(void *mem, size_t size) {} void krhino_task_abort_hook(ktask_t *task) {} #endif
YifuLiu/AliOS-Things
hardware/board/haaseduk1/config/k_config.c
C
apache-2.0
4,737
/* * Copyright (C) 2015-2017 Alibaba Group Holding Limited */ #ifndef K_CONFIG_H #define K_CONFIG_H /* kernel feature conf */ #ifndef RHINO_CONFIG_SEM #define RHINO_CONFIG_SEM 1 #endif #ifndef RHINO_CONFIG_QUEUE #define RHINO_CONFIG_QUEUE 1 #endif #ifndef RHINO_CONFIG_TASK_SEM #define RHINO_CONFIG_TASK_SEM 1 #endif #ifndef RHINO_CONFIG_EVENT_FLAG #define RHINO_CONFIG_EVENT_FLAG 1 #endif #ifndef RHINO_CONFIG_TIMER #define RHINO_CONFIG_TIMER 1 #endif #ifndef RHINO_CONFIG_BUF_QUEUE #define RHINO_CONFIG_BUF_QUEUE 1 #endif /* kernel task conf */ #ifndef RHINO_CONFIG_TASK_INFO #define RHINO_CONFIG_TASK_INFO 1 #endif #ifndef RHINO_CONFIG_TASK_DEL #define RHINO_CONFIG_TASK_DEL 1 #endif #ifndef RHINO_CONFIG_TASK_STACK_OVF_CHECK #define RHINO_CONFIG_TASK_STACK_OVF_CHECK 1 #endif #ifndef RHINO_CONFIG_SCHED_RR #define RHINO_CONFIG_SCHED_RR 1 #endif #ifndef RHINO_CONFIG_TIME_SLICE_DEFAULT #define RHINO_CONFIG_TIME_SLICE_DEFAULT 50 #endif #ifndef RHINO_CONFIG_PRI_MAX #define RHINO_CONFIG_PRI_MAX 62 #endif #ifndef RHINO_CONFIG_USER_PRI_MAX #define RHINO_CONFIG_USER_PRI_MAX (RHINO_CONFIG_PRI_MAX - 2) #endif /* kernel workqueue conf */ // #ifndef RHINO_CONFIG_WORKQUEUE #define RHINO_CONFIG_WORKQUEUE 1 // #endif #ifndef RHINO_CONFIG_WORKQUEUE_STACK_SIZE #define RHINO_CONFIG_WORKQUEUE_STACK_SIZE 768 #endif /* kernel timer&tick conf */ #ifndef RHINO_CONFIG_TICKS_PER_SECOND #define RHINO_CONFIG_TICKS_PER_SECOND 1000 #endif /* must reserve enough stack size for timer cb will consume */ #ifndef RHINO_CONFIG_TIMER_TASK_STACK_SIZE #define RHINO_CONFIG_TIMER_TASK_STACK_SIZE 2048 #endif #ifndef RHINO_CONFIG_TIMER_TASK_PRI #define RHINO_CONFIG_TIMER_TASK_PRI 5 #endif /* kernel intrpt conf */ #ifndef RHINO_CONFIG_INTRPT_STACK_OVF_CHECK #define RHINO_CONFIG_INTRPT_STACK_OVF_CHECK 0 #endif /* kernel dyn alloc conf */ #ifndef RHINO_CONFIG_KOBJ_DYN_ALLOC #define RHINO_CONFIG_KOBJ_DYN_ALLOC 1 #endif #if (RHINO_CONFIG_KOBJ_DYN_ALLOC > 0) #ifndef RHINO_CONFIG_K_DYN_TASK_STACK #define RHINO_CONFIG_K_DYN_TASK_STACK 256 #endif #ifndef RHINO_CONFIG_K_DYN_MEM_TASK_PRI #define RHINO_CONFIG_K_DYN_MEM_TASK_PRI 6 #endif #endif /* kernel idle conf */ #ifndef RHINO_CONFIG_IDLE_TASK_STACK_SIZE #define RHINO_CONFIG_IDLE_TASK_STACK_SIZE 1024 #endif /* kernel hook conf */ #ifndef RHINO_CONFIG_USER_HOOK #define RHINO_CONFIG_USER_HOOK 1 #endif #ifndef RHINO_CONFIG_CPU_NUM #define RHINO_CONFIG_CPU_NUM 1 #endif /* task user info index start */ #ifndef RHINO_CONFIG_TASK_INFO_NUM #define RHINO_CONFIG_TASK_INFO_NUM 5 #endif #ifndef PTHREAD_CONFIG_USER_INFO_POS #define PTHREAD_CONFIG_USER_INFO_POS 0 #endif #ifndef RHINO_TASK_HOOK_USER_INFO_POS #define RHINO_TASK_HOOK_USER_INFO_POS 1 #endif #ifndef RHINO_CLI_CONSOLE_USER_INFO_POS #define RHINO_CLI_CONSOLE_USER_INFO_POS 2 #endif #ifndef RHINO_ERRNO_USER_INFO_POS #define RHINO_ERRNO_USER_INFO_POS 3 #endif /* task user info index end */ #ifndef RHINO_CONFIG_SYS_STATS #define RHINO_CONFIG_SYS_STATS 1 #endif #ifndef RHINO_CONFIG_HW_COUNT #define RHINO_CONFIG_HW_COUNT 1 #endif #ifndef RHINO_CONFIG_MM_TRACE_LVL #define RHINO_CONFIG_MM_TRACE_LVL 0 #endif #ifndef RHINO_CONFIG_CLI_AS_NMI #define RHINO_CONFIG_CLI_AS_NMI 0 #endif #if (RHINO_CONFIG_CLI_AS_NMI > 0) #ifndef RHINO_CONFIG_NMI_OFFSET #define RHINO_CONFIG_NMI_OFFSET 40 #endif #endif #endif /* K_CONFIG_H */
YifuLiu/AliOS-Things
hardware/board/haaseduk1/config/k_config.h
C
apache-2.0
3,332
#ifndef NET_CONFIG_H #define NET_CONFIG_H #endif
YifuLiu/AliOS-Things
hardware/board/haaseduk1/config/net_config.h
C
apache-2.0
50
/* * Copyright (C) 2015-2021 Alibaba Group Holding Limited */ #include <aos/flashpart_core.h> #include <aos/hal/flash.h> static int flash_partitions_init(void) { static aos_flashpart_t partitions[] = { { .dev = { .id = HAL_PARTITION_BOOTLOADER, }, .flash_id = 0, .block_start = 0x0, .block_count = 0x10, }, { .dev = { .id = HAL_PARTITION_PARAMETER_3, }, .flash_id = 0, .block_start = 0x10, .block_count = 0x2, }, { .dev = { .id = HAL_PARTITION_BOOT1, }, .flash_id = 0, .block_start = 0x12, .block_count = 0x18, }, { .dev = { .id = HAL_PARTITION_APPLICATION, }, .flash_id = 0, .block_start = 0x2A, .block_count = 0x578, }, { .dev = { .id = HAL_PARTITION_BOOT1_REDUND, }, .flash_id = 0, .block_start = 0x5A2, .block_count = 0x18, }, { .dev = { .id = HAL_PARTITION_OTA_TEMP, }, .flash_id = 0, .block_start = 0x5BA, .block_count = 0x578, }, { .dev = { .id = HAL_PARTITION_LITTLEFS, }, .flash_id = 0, .block_start = 0xB32, .block_count = 0x4AE, }, { .dev = { .id = HAL_PARTITION_PARAMETER_4, }, .flash_id = 0, .block_start = 0xFE0, .block_count = 0x10, }, { .dev = { .id = HAL_PARTITION_PARAMETER_1, }, .flash_id = 0, .block_start = 0xFF0, .block_count = 0x1, }, { .dev = { .id = HAL_PARTITION_PARAMETER_2, }, .flash_id = 0, .block_start = 0xFF1, .block_count = 0xD, }, { .dev = { .id = HAL_PARTITION_ENV, }, .flash_id = 0, .block_start = 0xFFE, .block_count = 0x2, }, { .dev = { .id = HAL_PARTITION_ENV_REDUND, }, .flash_id = 0, .block_start = 0xFFE, .block_count = 0x2, }, }; for (size_t i = 0; i < sizeof(partitions) / sizeof(partitions[0]); i++) { int ret; ret = aos_flashpart_register(&partitions[i]); if (ret) { for (size_t j = 0; j < i; j++) (void)aos_flashpart_unregister(partitions[j].dev.id); return ret; } } return 0; } LEVEL1_DRIVER_ENTRY(flash_partitions_init)
YifuLiu/AliOS-Things
hardware/board/haaseduk1/config/partition_conf.c
C
apache-2.0
2,637
#include "aos/hal/flash.h" #include <stddef.h> /* Logic partition on flash devices */ const hal_logic_partition_t hal_partitions[] = { [HAL_PARTITION_BOOTLOADER] = { .partition_owner = HAL_FLASH_EMBEDDED, .partition_description = "boot1", .partition_start_addr = 0x0, .partition_length = 0x10000, // 64k bytes .partition_options = PAR_OPT_READ_EN | PAR_OPT_WRITE_EN, }, [HAL_PARTITION_PARAMETER_3] = { .partition_owner = HAL_FLASH_EMBEDDED, .partition_description = "boot_info", .partition_start_addr = 0x10000, // boot information need protect .partition_length = 0x2000, // 8k bytes .partition_options = PAR_OPT_READ_EN | PAR_OPT_WRITE_EN, }, [HAL_PARTITION_BOOT1] = { .partition_owner = HAL_FLASH_EMBEDDED, .partition_description = "boot2A", .partition_start_addr = 0x12000, .partition_length = 0x18000, // 64k bytes .partition_options = PAR_OPT_READ_EN | PAR_OPT_WRITE_EN, }, [HAL_PARTITION_APPLICATION] = { .partition_owner = HAL_FLASH_EMBEDDED, .partition_description = "RTOSA", .partition_start_addr = 0x2A000, .partition_length = 0x578000, // 5.5M bytes .partition_options = PAR_OPT_READ_EN | PAR_OPT_WRITE_EN, }, [HAL_PARTITION_BOOT1_REDUND] = { .partition_owner = HAL_FLASH_EMBEDDED, .partition_description = "boot2B", .partition_start_addr = 0x5A2000, .partition_length = 0x18000, // 64k bytes .partition_options = PAR_OPT_READ_EN | PAR_OPT_WRITE_EN, }, [HAL_PARTITION_OTA_TEMP] = { .partition_owner = HAL_FLASH_EMBEDDED, .partition_description = "RTOSB", .partition_start_addr = 0x5BA000, .partition_length = 0x578000, // 5.5M bytes .partition_options = PAR_OPT_READ_EN | PAR_OPT_WRITE_EN, }, [HAL_PARTITION_LITTLEFS] = { .partition_owner = HAL_FLASH_EMBEDDED, .partition_description = "littleFS", // for little fs module .partition_start_addr = 0xB32000, .partition_length = 0x4AE000, .partition_options = PAR_OPT_READ_EN | PAR_OPT_WRITE_EN, }, [HAL_PARTITION_PARAMETER_4] = { .partition_owner = HAL_FLASH_EMBEDDED, .partition_description = "boot1_sec", .partition_start_addr = 0xFE0000, .partition_length = 0x10000, // 64k bytes .partition_options = PAR_OPT_READ_EN | PAR_OPT_WRITE_EN, }, [HAL_PARTITION_PARAMETER_1] = { .partition_owner = HAL_FLASH_EMBEDDED, .partition_description = "boot2_info", .partition_start_addr = 0xFF0000, .partition_length = 0x1000, // 4k bytes .partition_options = PAR_OPT_READ_EN | PAR_OPT_WRITE_EN, }, [HAL_PARTITION_PARAMETER_2] = { .partition_owner = HAL_FLASH_EMBEDDED, .partition_description = "KV", // for KV module .partition_start_addr = 0xFF1000, .partition_length = 0xD000, // K bytes .partition_options = PAR_OPT_READ_EN | PAR_OPT_WRITE_EN, }, [HAL_PARTITION_ENV] = { .partition_owner = HAL_FLASH_EMBEDDED, .partition_description = "factory", .partition_start_addr = 0xFFE000, .partition_length = 0x2000, .partition_options = PAR_OPT_READ_EN | PAR_OPT_WRITE_EN, }, [HAL_PARTITION_ENV_REDUND] = { .partition_owner = HAL_FLASH_EMBEDDED, .partition_description = "factory_backup", .partition_start_addr = 0xFFE000, .partition_length = 0x2000, .partition_options = PAR_OPT_READ_EN | PAR_OPT_WRITE_EN, }, }; /* Declare a constant to indicate the defined partitions amount */ const size_t hal_partitions_amount = (sizeof(hal_partitions) / sizeof(hal_logic_partition_t));
YifuLiu/AliOS-Things
hardware/board/haaseduk1/config/partition_conf_legacy.c
C
apache-2.0
4,284
/* * Copyright (C) 2015-2020 Alibaba Group Holding Limited */ #include "di.h" #include "aos/kernel.h" #include "hal_iomux_haas1000.h" #include "ulog/ulog.h" #include <stdio.h> #define TAG "ex_di" #define TIMER_CHECK_INTERVAL 10 #define DI_STABLE_COUNT 5 digital_input_value_change_notify g_di_notify_cb = NULL; typedef struct { uint8_t installed; uint8_t monitor_flag; uint8_t check_count; gpio_pinstate_t exactly_level; gpio_dev_t gpio_dev; } gpio_dev_input_t; /*digital input gpio dev list , the default value is high*/ static gpio_dev_input_t gpio_dev_input[DI_PORT_SIZE] = { {0, 0, 0, GPIO_PinState_Set, {HAL_IOMUX_PIN_P2_4, IRQ_MODE, NULL} }, {0, 0, 0, GPIO_PinState_Set, {HAL_IOMUX_PIN_P2_5, IRQ_MODE, NULL} }, {0, 0, 0, GPIO_PinState_Set, {HAL_IOMUX_PIN_P4_7, IRQ_MODE, NULL} }, {0, 0, 0, GPIO_PinState_Set, {HAL_IOMUX_PIN_P4_6, IRQ_MODE, NULL} }, }; static aos_timer_t st_di_check_timer = {0}; static int32_t get_di_port_by_iomux(uint8_t iomux, uint32_t *diport) { uint32_t i = 0; for (i = 0; i < DI_PORT_SIZE; i++) { if (gpio_dev_input[i].gpio_dev.port == iomux) { *diport = i; return 0; } } return -1; } static void di_interrup_proc(void *arg) { uint8_t port = 0; uint32_t diport = 0; int32_t ret = 0; uint32_t value = 0; if (NULL == arg) { LOGE(TAG, "Invalid input %s %d", __FILE__, __LINE__); return; } port = *(uint8_t *)arg; ret = get_di_port_by_iomux(port, &diport); if (ret) { LOGE(TAG, "can not porc iomux %d interrupt", port); return; } if (gpio_dev_input[diport].installed == 0) { LOGE(TAG, "di port %d iomux %d haven't init yet", diport, port); return; } ret = hal_gpio_input_get(&(gpio_dev_input[diport].gpio_dev), &value); if (ret) { LOGE(TAG, "Fail to get di port %d input value ret %d", diport, value); return; } hal_gpio_clear_irq(&gpio_dev_input[diport].gpio_dev); hal_gpio_disable_irq(&gpio_dev_input[diport].gpio_dev); if (value != gpio_dev_input[diport].exactly_level) { /*add the port to the monitorlist list*/ // LOGI(TAG,"add di %d to monitor list", diport); gpio_dev_input[diport].check_count = 0; gpio_dev_input[diport].monitor_flag = 1; } if (value == GPIO_PinState_Set) { /*rising edge interrupt, so enable falling interrupt */ // LOGI(TAG, "port %d recv a rising edge interrupt and enable the // falling edge", diport); ret = hal_gpio_enable_irq(&gpio_dev_input[diport].gpio_dev, IRQ_TRIGGER_FALLING_EDGE, di_interrup_proc, &gpio_dev_input[diport].gpio_dev.port); } if (value == GPIO_PinState_Reset) { /*falling edge interrupt*/ // LOGI(TAG, "port %d recv a falling edge interrupt and enable the // rising edge", diport); ret = hal_gpio_enable_irq(&gpio_dev_input[diport].gpio_dev, IRQ_TRIGGER_RISING_EDGE, di_interrup_proc, &gpio_dev_input[diport].gpio_dev.port); } if (ret) { LOGE(TAG, "Fail to enable gpio interrupt , gpio value is %d, ret %d", value, ret); } return; } static void di_value_check(void *timer, void *arg) { uint32_t i; int32_t ret = 0; uint32_t gpio_value = 0; for (i = 0; i < DI_PORT_SIZE; i++) { if (gpio_dev_input[i].installed == 0 || gpio_dev_input[i].monitor_flag == 0) { continue; } ret = hal_gpio_input_get(&gpio_dev_input[i].gpio_dev, &gpio_value); if (ret) { LOGE(TAG, "Fail to get di %d port %d value at %s %d", i, gpio_dev_input[i].gpio_dev.port, __FILE__, __LINE__); continue; } if (gpio_value == gpio_dev_input[i].exactly_level) { /*remove it from standout monitor list*/ gpio_dev_input[i].monitor_flag = 0; gpio_dev_input[i].check_count = 0; } else { gpio_dev_input[i].check_count++; if (gpio_dev_input[i].check_count >= DI_STABLE_COUNT) { gpio_dev_input[i].monitor_flag = 0; gpio_dev_input[i].exactly_level = gpio_value; gpio_dev_input[i].check_count = 0; LOGI(TAG, "di %d changes to value %d", i, gpio_value); /*notify the gpio value change info */ if (NULL != g_di_notify_cb) { ret = g_di_notify_cb(i, gpio_value); if (ret) { LOGE(TAG, "Fail to notify di %d value changes to %d", i, gpio_value); } } } } } } int32_t expansion_board_di_init() { int32_t ret = 0; uint32_t i = 0; uint32_t gpio_value = GPIO_PinState_Set; /*init digital input*/ for (i = 0; i < DI_PORT_SIZE; i++) { ret = hal_gpio_init(&gpio_dev_input[i].gpio_dev); if (ret) { LOGE(TAG, "di %d pin %d init fail ret %d", i, gpio_dev_input[i].gpio_dev.port, ret); return -1; } ret = hal_gpio_input_get(&gpio_dev_input[i].gpio_dev, &gpio_value); if (ret) { LOGE(TAG, "di %d pin %d fail to get value, ret %d", i, gpio_dev_input[i].gpio_dev.port, ret); return -1; } LOGI(TAG, "di %d init value is %d", i, gpio_value); /*for haas1000 doesn't support both edge trigger*/ if (gpio_value == GPIO_PinState_Set) { ret = hal_gpio_enable_irq( &gpio_dev_input[i].gpio_dev, IRQ_TRIGGER_FALLING_EDGE, di_interrup_proc, &gpio_dev_input[i].gpio_dev.port); } else { ret = hal_gpio_enable_irq(&gpio_dev_input[i].gpio_dev, IRQ_TRIGGER_RISING_EDGE, di_interrup_proc, &gpio_dev_input[i].gpio_dev.port); } if (ret) { LOGE(TAG, "di %d pin %d fail enable irq ret %d", i, gpio_dev_input[i].gpio_dev.port, ret); return -1; } gpio_dev_input[i].installed = 1; gpio_dev_input[i].exactly_level = gpio_value; } /*init the gpio check timer, check gpio value every 10ms */ ret = aos_timer_new_ext(&st_di_check_timer, di_value_check, NULL, TIMER_CHECK_INTERVAL, 1, 1); if (ret) { LOGE(TAG, "Fail to new gpio value check timer ret 0x%x", ret); for (i = 0; i < DI_PORT_SIZE; i++) { hal_gpio_disable_irq(&gpio_dev_input[i].gpio_dev); hal_gpio_finalize(&gpio_dev_input[i].gpio_dev); gpio_dev_input[i].installed = 0; } return -1; } return 0; } int32_t expansion_board_di_get_value(uint8_t port, gpio_pinstate_t *value) { int32_t ret = 0; if (port >= DI_PORT_SIZE || NULL == value) { LOGE(TAG, " %s %d Invalid input port %d", __FILE__, __LINE__, port); return -1; } if (gpio_dev_input[port].installed == 0) { LOGE(TAG, "DI port %d haven't init yet", port); return -1; } *value = gpio_dev_input[port].exactly_level; return 0; } void expansion_board_di_change_notify_register( digital_input_value_change_notify cb) { if (NULL == cb) { LOGE(TAG, " %s %d Invalid input", __FILE__, __LINE__); return; } g_di_notify_cb = cb; }
YifuLiu/AliOS-Things
hardware/board/haaseduk1/drivers/di.c
C
apache-2.0
7,690
/* * Copyright (C) 2015-2020 Alibaba Group Holding Limited */ #ifndef GIDITAL_INPUT_H #define GIDITAL_INPUT_H #include "aos/hal/gpio.h" #include "stdint.h" enum en_di_port { DI_PORT_0 = 0, DI_PORT_1, DI_PORT_2, DI_PORT_3, DI_PORT_SIZE }; typedef int32_t (*digital_input_value_change_notify)(uint8_t port, uint32_t value); void expansion_board_di_change_notify_register( digital_input_value_change_notify cb); int32_t expansion_board_di_get_value(uint8_t port, gpio_pinstate_t *value); int32_t expansion_board_di_init(); #endif
YifuLiu/AliOS-Things
hardware/board/haaseduk1/drivers/di.h
C
apache-2.0
614
/* * Copyright (C) 2015-2020 Alibaba Group Holding Limited */ #include "do.h" #include "aos/kernel.h" #include "hal_iomux_haas1000.h" #include "ulog/ulog.h" #include <stdio.h> #define TAG "ex_do" typedef struct { uint8_t installed; gpio_dev_t gpio_dev; } gpio_dev_ouput_t; /*digital input gpio dev list , the default value is high*/ static gpio_dev_ouput_t gpio_dev_output[DO_PORT_SIZE] = { {0, {HAL_IOMUX_PIN_P2_2, OUTPUT_PUSH_PULL, NULL}}, //UART2_RXD {0, {HAL_IOMUX_PIN_P2_3, OUTPUT_PUSH_PULL, NULL}}, //UART2_TXD {0, {HAL_IOMUX_PIN_P0_4, OUTPUT_PUSH_PULL, NULL}}, //GPIO_P04 {0, {HAL_IOMUX_PIN_P0_5, OUTPUT_PUSH_PULL, NULL}}, //GPIO_P05 {0, {HAL_IOMUX_PIN_P0_6, OUTPUT_PUSH_PULL, NULL}}, //GPIO_P06 {0, {HAL_IOMUX_PIN_P0_7, OUTPUT_PUSH_PULL, NULL}}, //GPIO_P07 {0, {HAL_IOMUX_PIN_P0_0, OUTPUT_PUSH_PULL, NULL}}, //SWCLK {0, {HAL_IOMUX_PIN_P0_1, OUTPUT_PUSH_PULL, NULL}}, //SWDIO }; int32_t expansion_board_do_init(void) { int32_t ret = 0; uint32_t i = 0; /*init digital input*/ for (i = 0; i < DO_PORT_SIZE; i++) { ret = hal_gpio_init(&gpio_dev_output[i].gpio_dev); if (ret) { LOGE(TAG, "do %d pin %d init fail ret %d", i, gpio_dev_output[i].gpio_dev.port, ret); return -1; } /*init status do should output low, depends on pd requires */ ret = hal_gpio_output_high(&gpio_dev_output[i].gpio_dev); if (ret) { LOGE(TAG, "%s %d port %d set low fail , ret %d", __func__, __LINE__, i, ret); return -1; } gpio_dev_output[i].installed = 1; } return 0; } int32_t expansion_board_do_high(uint8_t port) { int32_t ret = -1; if (port >= DO_PORT_SIZE) { LOGE(TAG, "%s %d invalid input port %d", __func__, __LINE__, port); return -1; } if (gpio_dev_output[port].installed == 0) { LOGE(TAG, "%s %d port %d haven't init yet", __func__, __LINE__, port); return -1; } /*do output high ,gpio should pull down */ ret = hal_gpio_output_high(&gpio_dev_output[port].gpio_dev); if (ret) { LOGE(TAG, "%s %d port %d set high fail , ret %d", __func__, __LINE__, port, ret); return -1; } return 0; } int32_t expansion_board_do_low(uint8_t port) { int32_t ret = -1; if (port >= DO_PORT_SIZE) { LOGE(TAG, "%s %d invalid input port %d", __func__, __LINE__, port); return -1; } if (gpio_dev_output[port].installed == 0) { LOGE(TAG, "%s %d port %d haven't init yet", __func__, __LINE__, port); return -1; } /*do output high ,gpio should pull up */ ret = hal_gpio_output_low(&gpio_dev_output[port].gpio_dev); if (ret) { LOGE(TAG, "%s %d port %d set low fail , ret %d", __func__, __LINE__, port, ret); return -1; } return 0; }
YifuLiu/AliOS-Things
hardware/board/haaseduk1/drivers/do.c
C
apache-2.0
2,963
/* * Copyright (C) 2015-2020 Alibaba Group Holding Limited */ #ifndef GIDITAL_OUTPUT_H #define GIDITAL_OUTPUT_H #include "aos/hal/gpio.h" #include "stdint.h" enum en_do_port { DO_PORT_0 = 0, DO_PORT_1, DO_PORT_2, DO_PORT_3, DO_PORT_4, DO_PORT_5, DO_PORT_6, DO_PORT_7, DO_PORT_SIZE }; int32_t expansion_board_do_init(void); int32_t expansion_board_do_high(uint8_t port); int32_t expansion_board_do_low(uint8_t port); #endif
YifuLiu/AliOS-Things
hardware/board/haaseduk1/drivers/do.h
C
apache-2.0
468
/* * Copyright (C) 2015-2020 Alibaba Group Holding Limited */ #include "exp_adc.h" #include "aos/kernel.h" #include "hal_iomux_haas1000.h" #include "ulog/ulog.h" #include <stdio.h> #define TAG "ex_adc" typedef struct { uint8_t installed; adc_dev_t st_adc_info; } exp_adc_dev_t; #define ADC_DEFAULT_TIMEOUT 3000 #define ADC_MAX_VALUE 3300 #define ADC_AVERAGE_TIME 32 /*exp adc device*/ static exp_adc_dev_t exp_adc_dev[ADC_PORT_SIZE] = { {0, {2, {1000}, NULL}}, // not installed {0, {1, {1000}, NULL}}, {0, {0, {1000}, NULL}}, }; int32_t expansion_board_adc_init(void) { int32_t ret = 0; int32_t i = 0; for (i = 0; i < ADC_PORT_SIZE; i++) { if (exp_adc_dev[i].installed) { continue; } ret = hal_adc_init(&exp_adc_dev[i].st_adc_info); if (ret) { LOGE(TAG, "adc port %d init fail %d ", i, ret); return -1; } exp_adc_dev[i].installed = 1; } return 0; } int32_t expansion_board_adc_get_value(uint32_t port, uint32_t *adc_value) { int32_t ret = 0; uint32_t i = 0; uint32_t adc_sum = 0; uint32_t adc_avrg = 0; /*for haas1000 adc max value */ uint32_t adc_min = ADC_MAX_VALUE; uint32_t adc_max = 0; if (port >= ADC_PORT_SIZE || NULL == adc_value) { LOGE(TAG, "%s %d invalid input port %d", __FILE__, __LINE__, port); return -1; } if (exp_adc_dev[port].installed == 0) { LOGE(TAG, "exp adc %d haven't init yet , get value fail", port); return -1; } ret = hal_adc_value_get(&exp_adc_dev[port].st_adc_info, adc_value, ADC_DEFAULT_TIMEOUT); if (ret) { LOGE(TAG, "Get adc %d port value fail ", port); return -1; } return 0; } int32_t board_get_voltage(uint32_t port, uint32_t *output) { int32_t ret = 0; uint32_t i = 0; uint32_t adc_sum = 0; uint32_t adc_avrg = 0; /*for haas1000 adc max value */ uint32_t adc_min = ADC_MAX_VALUE; uint32_t adc_max = 0; uint32_t adc_value = 0; for (i = 0; i < ADC_AVERAGE_TIME + 2; i++) { ret = expansion_board_adc_get_value(port, &adc_value); if (ret) { LOGE(TAG, "Get adc %d port value fail ", port); return -1; } adc_sum += adc_value; /* the min sampling voltage */ if (adc_min >= adc_value) { adc_min = output; } /* the max sampling voltage */ if (adc_max <= output) { adc_max = output; } aos_msleep(20); } /*adc sum value reduce adc min value reduse adc max value; and divided by * 32*/ adc_avrg = (adc_sum - adc_min - adc_max) >> 5; *output = adc_avrg; return 0; }
YifuLiu/AliOS-Things
hardware/board/haaseduk1/drivers/exp_adc.c
C
apache-2.0
2,790
/* * Copyright (C) 2015-2020 Alibaba Group Holding Limited */ #ifndef EXP_ADC_H #define EXP_ADC_H #include "aos/hal/adc.h" #include "stdint.h" enum en_exp_adc_port { ADC_PORT_0 = 0, ADC_PORT_1, ADC_PORT_2, ADC_PORT_SIZE }; int32_t expansion_board_adc_init(void); int32_t expansion_board_adc_get_value(uint32_t port, uint32_t *adc_value); int32_t board_get_voltage(uint32_t port, uint32_t *output); #endif
YifuLiu/AliOS-Things
hardware/board/haaseduk1/drivers/exp_adc.h
C
apache-2.0
413
#include "key.h" #include "aos/hal/gpio.h" #include "hal_iomux_haas1000.h" #include "ulog/ulog.h" #include <aos/kernel.h> #include <stdio.h> #include <vfsdev/gpio_dev.h> #define TAG "key_poll" #define EDK_BOARD_KEY1 HAL_IOMUX_PIN_P2_7 #define EDK_BOARD_KEY2 HAL_IOMUX_PIN_P2_4 #define EDK_BOARD_KEY3 HAL_IOMUX_PIN_P2_5 #define EDK_BOARD_KEY4 HAL_IOMUX_PIN_P3_2 #define KEY_NUM 4 #define TIMER_CHECK_INTERVAL 30 #define DI_STABLE_COUNT 4 #define USING_VFS_GPIO static key_code_cb notify_key_code_cb = NULL; static aos_timer_t key_poll_timer = {0}; static int32_t g_gpio_fd = -1; typedef struct { uint8_t key_code; uint8_t check_count; } key_value_t; static key_value_t key_value; typedef struct { uint8_t installed; uint8_t monitor_flag; uint8_t check_count; gpio_dev_t gpio_dev; } key_dev_input_t; /*digital input gpio dev list , the default value is high*/ static key_dev_input_t key_dev_input[KEY_NUM] = { {0, 0, 0, {EDK_BOARD_KEY1, IRQ_MODE, NULL} }, {0, 0, 0, {EDK_BOARD_KEY2, IRQ_MODE, NULL} }, {0, 0, 0, {EDK_BOARD_KEY3, IRQ_MODE, NULL} }, {0, 0, 0, {EDK_BOARD_KEY4, IRQ_MODE, NULL} }, }; static void key_rising_edge_handle(gpio_dev_t *gpio); static void key_falling_edge_handle(gpio_dev_t *gpio); int find_key_index(gpio_dev_t *gpio) { int index = -1; gpio_dev_t *key_gpio = gpio; if (key_gpio == NULL) { return index; } switch (key_gpio->port) { case EDK_BOARD_KEY1: index = 0; break; case EDK_BOARD_KEY2: index = 1; break; case EDK_BOARD_KEY3: index = 2; break; case EDK_BOARD_KEY4: index = 3; break; } //printf("%s, index : %d\n", __func__, index); return index; } static void key_poll(void *timer, void *arg) { uint32_t i; int32_t ret = 0; uint32_t gpio_value = 0; uint8_t key_code = 0; for (i = 0; i < KEY_NUM; i++) { if (key_dev_input[i].installed == 0 || key_dev_input[i].monitor_flag == 0) { continue; } #ifdef USING_VFS_GPIO int ret = 0; gpio_io_config_t config; config.id = key_dev_input[i].gpio_dev.port; config.config = GPIO_IO_INPUT | GPIO_IO_INPUT_PU; config.data = 0; ret = ioctl(g_gpio_fd, IOC_GPIO_GET, &config); if (ret) { LOGE(TAG, "get gpio:%d failed, ret %d", config.id, ret); return; } #else ret = hal_gpio_input_get(&key_dev_input[i].gpio_dev, &gpio_value); if (ret) { LOGE(TAG, "Fail to get di %d port %d value at %s %d", i, key_dev_input[i].gpio_dev.port, __FILE__, __LINE__); continue; } #endif if (gpio_value == GPIO_PinState_Reset) { //printf(" %d key is pressing\n", i); key_code = key_code | (0x01 << i); } } if ((key_value.key_code == key_code) && (key_value.key_code != 0)) { key_value.check_count++; } else { key_value.key_code = key_code; key_value.check_count = 0; } if (key_value.check_count >= DI_STABLE_COUNT) { key_value.check_count = 0; LOGI(TAG, "notify %d in key_poll\n", key_value.key_code); if (key_value.key_code) { notify_key_code_cb(key_value.key_code); } } } static void key_rising_edge_handle(gpio_dev_t *gpio) { int index = -1; gpio_dev_t *key_gpio = gpio; index = find_key_index(key_gpio); if (index < 0 || index >= KEY_NUM) { printf("err in %s:%d\n", __func__, __LINE__); return; } //printf(" %d key release\n", index); key_dev_input[index].check_count = 0; key_dev_input[index].monitor_flag = 0; #ifdef USING_VFS_GPIO int ret = 0; gpio_irq_config_t irq_config; irq_config.id = key_gpio->port; irq_config.config = GPIO_IRQ_CLEAR; ret = ioctl(g_gpio_fd, IOC_GPIO_SET_IRQ, &irq_config); if (ret) { LOGE(TAG, "clear gpio irq:%d failed, ret %d", key_gpio->port, ret); return; } irq_config.config = GPIO_IRQ_DISABLE; ret = ioctl(g_gpio_fd, IOC_GPIO_SET_IRQ, &irq_config); if (ret) { LOGE(TAG, "clear gpio irq:%d failed, ret %d", key_gpio->port, ret); return; } irq_config.id = key_gpio->port; irq_config.config = GPIO_IRQ_ENABLE | GPIO_IRQ_EDGE_FALLING; irq_config.cb = key_falling_edge_handle; irq_config.arg = key_gpio; ret = ioctl(g_gpio_fd, IOC_GPIO_SET_IRQ, &irq_config); if (ret) { LOGE(TAG, "enable gpio irq: failed, ret %d", ret); return; } #else hal_gpio_clear_irq(key_gpio); hal_gpio_disable_irq(key_gpio); hal_gpio_enable_irq(key_gpio, IRQ_TRIGGER_FALLING_EDGE, key_falling_edge_handle, key_gpio); #endif } static void key_falling_edge_handle(gpio_dev_t *gpio) { int index = -1; gpio_dev_t *key_gpio = gpio; index = find_key_index(key_gpio); if (index < 0 || index >= KEY_NUM) { printf("err in %s:%d\n", __func__, __LINE__); return; } //printf(" %d key press\n", index); #ifdef USING_VFS_GPIO int ret = -1; gpio_irq_config_t irq_config; irq_config.id = key_gpio->port; irq_config.config = GPIO_IRQ_CLEAR; ret = ioctl(g_gpio_fd, IOC_GPIO_SET_IRQ, &irq_config); if (ret) { LOGE(TAG, "clear gpio irq:%d failed, ret %d", key_gpio->port, ret); return; } irq_config.config = GPIO_IRQ_DISABLE; ret = ioctl(g_gpio_fd, IOC_GPIO_SET_IRQ, &irq_config); if (ret) { LOGE(TAG, "clear gpio irq:%d failed, ret %d", key_gpio->port, ret); return; } key_dev_input[index].check_count = 0; key_dev_input[index].monitor_flag = 1; irq_config.id = key_gpio->port; irq_config.config = GPIO_IRQ_ENABLE | GPIO_IRQ_EDGE_RISING; irq_config.cb = key_rising_edge_handle; irq_config.arg = key_gpio; ret = ioctl(g_gpio_fd, IOC_GPIO_SET_IRQ, &irq_config); if (ret) { LOGE(TAG, "enable gpio irq: failed, ret %d", ret); return; } #else hal_gpio_clear_irq(key_gpio); hal_gpio_disable_irq(key_gpio); key_dev_input[index].check_count = 0; key_dev_input[index].monitor_flag = 1; hal_gpio_enable_irq(key_gpio, IRQ_TRIGGER_RISING_EDGE, key_rising_edge_handle, key_gpio); #endif } int key_init(key_code_cb key_func) { int32_t ret = 0; uint32_t i = 0; printf("enter %s:%d\n", __func__, __LINE__); if (key_func) { notify_key_code_cb = key_func; } else { return -1; } #ifdef USING_VFS_GPIO gpio_irq_config_t irq_config; g_gpio_fd = open("/dev/gpio", 0); if (g_gpio_fd < 0) { printf("open /dev/gpio failed\n"); return -1; } #endif for (i = 0; i < KEY_NUM; i++) { #ifdef USING_VFS_GPIO irq_config.id = key_dev_input[i].gpio_dev.port; irq_config.config = GPIO_IRQ_ENABLE | GPIO_IRQ_EDGE_FALLING; irq_config.cb = key_falling_edge_handle; irq_config.arg = &key_dev_input[i].gpio_dev; ret = ioctl(g_gpio_fd, IOC_GPIO_SET_IRQ, &irq_config); if (ret) { LOGE(TAG, "di %d pin %d fail enable irq ret %d", i, key_dev_input[i].gpio_dev.port, ret); return -1; } #else ret = hal_gpio_init(&key_dev_input[i].gpio_dev); if (ret) { LOGE(TAG, "di %d pin %d init fail ret", i, key_dev_input[i].gpio_dev.port, ret); return -1; } ret = hal_gpio_enable_irq( &key_dev_input[i].gpio_dev, IRQ_TRIGGER_FALLING_EDGE, key_falling_edge_handle, &key_dev_input[i].gpio_dev); if (ret) { LOGE(TAG, "di %d pin %d fail enable irq ret %d", i, key_dev_input[i].gpio_dev.port, ret); return -1; } #endif key_dev_input[i].installed = 1; } /*init the gpio check timer, check gpio value every 30ms */ ret = aos_timer_new_ext(&key_poll_timer, key_poll, NULL, TIMER_CHECK_INTERVAL, 1, 1); if (ret) { LOGE(TAG, "Fail to new gpio value check timer ret 0x%x", ret); for (i = 0; i < KEY_NUM; i++) { #ifdef USING_VFS_GPIO irq_config.id = key_dev_input[i].gpio_dev.port; irq_config.config = GPIO_IRQ_DISABLE; irq_config.cb = key_falling_edge_handle; irq_config.arg = &key_dev_input[i].gpio_dev; ret = ioctl(g_gpio_fd, IOC_GPIO_SET_IRQ, &irq_config); if (ret) { LOGE(TAG, "di %d pin %d fail enable irq ret %d", i, key_dev_input[i].gpio_dev.port, ret); return -1; } #else hal_gpio_disable_irq(&key_dev_input[i].gpio_dev); hal_gpio_finalize(&key_dev_input[i].gpio_dev); #endif key_dev_input[i].installed = 0; } #ifdef USING_VFS_GPIO if (g_gpio_fd >= 0) { close(g_gpio_fd); g_gpio_fd = -1; } #endif return -1; } return 0; }
YifuLiu/AliOS-Things
hardware/board/haaseduk1/drivers/key.c
C
apache-2.0
9,173
/* * Copyright (C) 2015-2020 Alibaba Group Holding Limited */ #ifndef KEY_POLL_H #define KEY_POLL_H #include "stdint.h" typedef enum { EDK_KEY_1 = 0b0001, EDK_KEY_2 = 0b0010, EDK_KEY_3 = 0b0100, EDK_KEY_4 = 0b1000, } edk_keycode_t; typedef uint8_t key_code_t; typedef void (*key_code_cb)(key_code_t key_code); int key_init(key_code_cb key_func); #endif // KEY_POLL_H
YifuLiu/AliOS-Things
hardware/board/haaseduk1/drivers/key.h
C
apache-2.0
390
#include "led.h" #include "aos/hal/gpio.h" #include "hal_iomux_haas1000.h" void led_switch(led_num_e id, led_e onoff) { int ret = 0; gpio_dev_t led; /* gpio port config */ switch (id) { case 1: led.port = HAL_IOMUX_PIN_P4_4; break; case 2: led.port = HAL_IOMUX_PIN_P4_3; break; case 3: led.port = HAL_IOMUX_PIN_P4_2; break; default: return; } /* set as output mode */ led.config = OUTPUT_PUSH_PULL; ret = hal_gpio_init(&led); if (ret != 0) { printf("hal_gpio_init %d failed, ret=%d\n", id, ret); return; } if(onoff == LED_ON) { ret = hal_gpio_output_high(&led); } else { ret = hal_gpio_output_low(&led); } if (ret != 0) { printf("hal_gpio_output %d failed, ret=%d\n", id, ret); return; } }
YifuLiu/AliOS-Things
hardware/board/haaseduk1/drivers/led.c
C
apache-2.0
890
/* * Copyright (C) 2015-2020 Alibaba Group Holding Limited */ #ifndef K_LED_H #define K_LED_H typedef enum { LED_OFF, LED_ON } led_e; typedef enum { LED1_NUM = 1, LED2_NUM = 2, LED3_NUM = 3 } led_num_e; void led_switch(led_num_e id, led_e onoff); #endif
YifuLiu/AliOS-Things
hardware/board/haaseduk1/drivers/led.h
C
apache-2.0
260
/* * Copyright (C) 2015-2020 Alibaba Group Holding Limited */ #ifndef HAL_OLED_H__ #define HAL_OLED_H__ #include "sh1106.h" // TODO // #include "sh1106/sh1106.h" //tmp #endif
YifuLiu/AliOS-Things
hardware/board/haaseduk1/drivers/oled/hal_oled.h
C
apache-2.0
179
/* * Copyright (C) 2015-2020 Alibaba Group Holding Limited */ #include "drv_acc_gyro_inv_mpu6050.h" #include "aos/hal/i2c.h" #include "aos/kernel.h" #include "hal_iomux_haas1000.h" #include "ulog/ulog.h" #include <stdio.h> #include <stdlib.h> static i2c_dev_t i2c_dev; // wtite one byte to register uint8_t MPU_Write_Byte(uint8_t reg, uint8_t data) { uint8_t *write_buf[2]; write_buf[0] = reg; write_buf[1] = data; sensor_i2c_master_send(MPU_I2C_PORT, MPU_ADDR, write_buf, 2, 1000); return 0; } // read byte from register uint8_t MPU_Read_Byte(uint8_t reg) { uint8_t data; sensor_i2c_master_send(MPU_I2C_PORT, MPU_ADDR, &reg, 1, 1000); aos_msleep(2); sensor_i2c_master_recv(MPU_I2C_PORT, MPU_ADDR, &data, 1, 1000); return data; } // write nbytes to register void MPU_Write_Len(uint8_t reg, uint8_t len, uint8_t *buf) { uint8_t *write_buf[100] = {0}; if ((len > 100) || (buf == NULL)) return; write_buf[0] = reg; memcpy(&write_buf[1], buf, len); sensor_i2c_master_send(MPU_I2C_PORT, MPU_ADDR, &write_buf, len + 1, 1000); } // read nbytes from register void MPU_Read_Len(uint8_t reg, uint8_t len, uint8_t *buf) { sensor_i2c_master_send(MPU_I2C_PORT, MPU_ADDR, &reg, 1, 1000); aos_msleep(2); sensor_i2c_master_recv(MPU_I2C_PORT, MPU_ADDR, buf, len, 1000); } // 设置MPU6050陀螺仪传感器满量程范围 // fsr:0,±250dps;1,±500dps;2,±1000dps;3,±2000dps // 返回值:0,设置成功 // 其他,设置失败 uint8_t MPU_Set_Gyro_Fsr(uint8_t fsr) { return MPU_Write_Byte(MPU_GYRO_CFG_REG, fsr << 3); // 设置陀螺仪满量程范围 } // 设置MPU6050加速度传感器满量程范围 // fsr:0,±2g;1,±4g;2,±8g;3,±16g // 返回值:0,设置成功 // 其他,设置失败 uint8_t MPU_Set_Accel_Fsr(uint8_t fsr) { return MPU_Write_Byte(MPU_ACCEL_CFG_REG, fsr << 3); // 设置加速度传感器满量程范围 } // 设置MPU6050的数字低通滤波器 // lpf:数字低通滤波频率(Hz) // 返回值:0,设置成功 // 其他,设置失败 uint8_t MPU_Set_LPF(u16 lpf) { uint8_t data = 0; if (lpf >= 188) data = 1; else if (lpf >= 98) data = 2; else if (lpf >= 42) data = 3; else if (lpf >= 20) data = 4; else if (lpf >= 10) data = 5; else data = 6; return MPU_Write_Byte(MPU_CFG_REG, data); // 设置数字低通滤波器 } // 设置MPU6050的采样率(假定Fs=1KHz) // rate:4~1000(Hz) // 返回值:0,设置成功 // 其他,设置失败 uint8_t MPU_Set_Rate(u16 rate) { uint8_t data; if (rate > 1000) rate = 1000; if (rate < 4) rate = 4; data = 1000 / rate - 1; MPU_Write_Byte(MPU_SAMPLE_RATE_REG, data); // 设置数字低通滤波器 return MPU_Set_LPF(rate / 2); // 自动设置LPF为采样率的一半 } // 初始化MPU6050 // 返回值:0,成功 // 其他,错误代码 uint8_t MPU_Init(void) { uint8_t device_id = 0; int32_t ret = sensor_i2c_open (MPU_I2C_PORT, MPU_ADDR, I2C_BUS_BIT_RATES_100K, 0); if (ret) { LOGE("SENSOR", "sensor i2c open failed, ret:%d\n", ret); return -EIO; } MPU_Write_Byte(MPU_PWR_MGMT1_REG, 0X80); // 复位MPU6050 aos_msleep(100); MPU_Write_Byte(MPU_PWR_MGMT1_REG, 0X00); // 唤醒MPU6050 MPU_Set_Gyro_Fsr(3); // 陀螺仪传感器,±2000dps MPU_Set_Accel_Fsr(0); // 加速度传感器,±2g MPU_Set_Rate(50); // 设置采样率50Hz MPU_Write_Byte(MPU_INT_EN_REG, 0X00); // 关闭所有中断 MPU_Write_Byte(MPU_USER_CTRL_REG, 0X00); // I2C主模式关闭 MPU_Write_Byte(MPU_FIFO_EN_REG, 0X00); // 关闭FIFO MPU_Write_Byte(MPU_INTBP_CFG_REG, 0X80); // INT引脚低电平有效 device_id = MPU_Read_Byte(MPU_DEVICE_ID_REG); if (device_id == MPU_DEV_ID) { // 器件ID正确 LOGI("SENSOR", "MPU init OK\n"); MPU_Write_Byte(MPU_PWR_MGMT1_REG, 0X01); // 设置CLKSEL,PLL X轴为参考 MPU_Write_Byte(MPU_PWR_MGMT2_REG, 0X00); // 加速度与陀螺仪都工作 MPU_Set_Rate(50); // 设置采样率为50Hz } else { LOGE("SENSOR", "MPU init Error -- %x\n", device_id); return 1; } return 0; } // 得到温度值 // 返回值:温度值(扩大了100倍) float MPU_Get_Temperature(void) { uint8_t buf[2]; short raw; float temp; MPU_Read_Len(MPU_TEMP_OUTH_REG, 2, buf); raw = ((u16)buf[0] << 8) | buf[1]; temp = 36.53 + ((double)raw) / 340; return temp; ; } // 得到陀螺仪值(原始值) // gx,gy,gz:陀螺仪x,y,z轴的原始读数(带符号) // 返回值:0,成功 // 其他,错误代码 void MPU_Get_Gyroscope(short *gx, short *gy, short *gz) { uint8_t buf[6]; MPU_Read_Len(MPU_GYRO_XOUTH_REG, 6, buf); *gx = ((u16)buf[0] << 8) | buf[1]; *gy = ((u16)buf[2] << 8) | buf[3]; *gz = ((u16)buf[4] << 8) | buf[5]; } // 得到加速度值(原始值) // gx,gy,gz:陀螺仪x,y,z轴的原始读数(带符号) // 返回值:0,成功 // 其他,错误代码 void MPU_Get_Accelerometer(short *ax, short *ay, short *az) { uint8_t buf[6]; MPU_Read_Len(MPU_ACCEL_XOUTH_REG, 6, buf); *ax = ((u16)buf[0] << 8) | buf[1]; *ay = ((u16)buf[2] << 8) | buf[3]; *az = ((u16)buf[4] << 8) | buf[5]; } void MPU_Deinit(void) { int32_t ret = sensor_i2c_close(MPU_I2C_PORT); if (ret) { LOGE("SENSOR", "sensor i2c close failed, ret:%d\n", ret); } return; }
YifuLiu/AliOS-Things
hardware/board/haaseduk1/drivers/sensor/drv_acc_gyro_inv_mpu6050.c
C
apache-2.0
5,543
/* * Copyright (C) 2015-2020 Alibaba Group Holding Limited */ #ifndef _MPU6050_H #define _MPU6050_H #include "k_api.h" #include <math.h> #include <stdbool.h> // #include "inv_mpu_dmp_motion_driver.h" // #define MPU_ACCEL_OFFS_REG 0X06 // accel_offs寄存器,可读取版本号,寄存器手册未提到 // #define MPU_PROD_ID_REG 0X0C // prod id寄存器,在寄存器手册未提到 #define MPU_SELF_TESTX_REG 0X0D // 自检寄存器X #define MPU_SELF_TESTY_REG 0X0E // 自检寄存器Y #define MPU_SELF_TESTZ_REG 0X0F // 自检寄存器Z #define MPU_SELF_TESTA_REG 0X10 // 自检寄存器A #define MPU_SAMPLE_RATE_REG 0X19 // 采样频率分频器 #define MPU_CFG_REG 0X1A // 配置寄存器 #define MPU_GYRO_CFG_REG 0X1B // 陀螺仪配置寄存器 #define MPU_ACCEL_CFG_REG 0X1C // 加速度计配置寄存器 #define MPU_MOTION_DET_REG 0X1F // 运动检测阀值设置寄存器 #define MPU_FIFO_EN_REG 0X23 // FIFO使能寄存器 #define MPU_I2CMST_CTRL_REG 0X24 // IIC主机控制寄存器 #define MPU_I2CSLV0_ADDR_REG 0X25 // IIC从机0器件地址寄存器 #define MPU_I2CSLV0_REG 0X26 // IIC从机0数据地址寄存器 #define MPU_I2CSLV0_CTRL_REG 0X27 // IIC从机0控制寄存器 #define MPU_I2CSLV1_ADDR_REG 0X28 // IIC从机1器件地址寄存器 #define MPU_I2CSLV1_REG 0X29 // IIC从机1数据地址寄存器 #define MPU_I2CSLV1_CTRL_REG 0X2A // IIC从机1控制寄存器 #define MPU_I2CSLV2_ADDR_REG 0X2B // IIC从机2器件地址寄存器 #define MPU_I2CSLV2_REG 0X2C // IIC从机2数据地址寄存器 #define MPU_I2CSLV2_CTRL_REG 0X2D // IIC从机2控制寄存器 #define MPU_I2CSLV3_ADDR_REG 0X2E // IIC从机3器件地址寄存器 #define MPU_I2CSLV3_REG 0X2F // IIC从机3数据地址寄存器 #define MPU_I2CSLV3_CTRL_REG 0X30 // IIC从机3控制寄存器 #define MPU_I2CSLV4_ADDR_REG 0X31 // IIC从机4器件地址寄存器 #define MPU_I2CSLV4_REG 0X32 // IIC从机4数据地址寄存器 #define MPU_I2CSLV4_DO_REG 0X33 // IIC从机4写数据寄存器 #define MPU_I2CSLV4_CTRL_REG 0X34 // IIC从机4控制寄存器 #define MPU_I2CSLV4_DI_REG 0X35 // IIC从机4读数据寄存器 #define MPU_I2CMST_STA_REG 0X36 // IIC主机状态寄存器 #define MPU_INTBP_CFG_REG 0X37 // 中断/旁路设置寄存器 #define MPU_INT_EN_REG 0X38 // 中断使能寄存器 #define MPU_INT_STA_REG 0X3A // 中断状态寄存器 #define MPU_ACCEL_XOUTH_REG 0X3B // 加速度值,X轴高8位寄存器 #define MPU_ACCEL_XOUTL_REG 0X3C // 加速度值,X轴低8位寄存器 #define MPU_ACCEL_YOUTH_REG 0X3D // 加速度值,Y轴高8位寄存器 #define MPU_ACCEL_YOUTL_REG 0X3E // 加速度值,Y轴低8位寄存器 #define MPU_ACCEL_ZOUTH_REG 0X3F // 加速度值,Z轴高8位寄存器 #define MPU_ACCEL_ZOUTL_REG 0X40 // 加速度值,Z轴低8位寄存器 #define MPU_TEMP_OUTH_REG 0X41 // 温度值高八位寄存器 #define MPU_TEMP_OUTL_REG 0X42 // 温度值低8位寄存器 #define MPU_GYRO_XOUTH_REG 0X43 // 陀螺仪值,X轴高8位寄存器 #define MPU_GYRO_XOUTL_REG 0X44 // 陀螺仪值,X轴低8位寄存器 #define MPU_GYRO_YOUTH_REG 0X45 // 陀螺仪值,Y轴高8位寄存器 #define MPU_GYRO_YOUTL_REG 0X46 // 陀螺仪值,Y轴低8位寄存器 #define MPU_GYRO_ZOUTH_REG 0X47 // 陀螺仪值,Z轴高8位寄存器 #define MPU_GYRO_ZOUTL_REG 0X48 // 陀螺仪值,Z轴低8位寄存器 #define MPU_I2CSLV0_DO_REG 0X63 // IIC从机0数据寄存器 #define MPU_I2CSLV1_DO_REG 0X64 // IIC从机1数据寄存器 #define MPU_I2CSLV2_DO_REG 0X65 // IIC从机2数据寄存器 #define MPU_I2CSLV3_DO_REG 0X66 // IIC从机3数据寄存器 #define MPU_I2CMST_DELAY_REG 0X67 // IIC主机延时管理寄存器 #define MPU_SIGPATH_RST_REG 0X68 // 信号通道复位寄存器 #define MPU_MDETECT_CTRL_REG 0X69 // 运动检测控制寄存器 #define MPU_USER_CTRL_REG 0X6A // 用户控制寄存器 #define MPU_PWR_MGMT1_REG 0X6B // 电源管理寄存器1 #define MPU_PWR_MGMT2_REG 0X6C // 电源管理寄存器2 #define MPU_FIFO_CNTH_REG 0X72 // FIFO计数寄存器高八位 #define MPU_FIFO_CNTL_REG 0X73 // FIFO计数寄存器低八位 #define MPU_FIFO_RW_REG 0X74 // FIFO读写寄存器 #define MPU_DEVICE_ID_REG 0X75 // 器件ID寄存器 // 如果AD0脚(9脚)接地,IIC地址为0X68(不包含最低位). // 如果接V3.3,则IIC地址为0X69(不包含最低位). #define MPU_I2C_PORT 0x1 #define MPU_ADDR 0X69 #define MPU_DEV_ID 0x68 // 因为模块AD0默认接GND,所以转为读写地址后,为0XD1和0XD0(如果接VCC,则为0XD3和0XD2) // #define MPU_READ 0XD1 // #define MPU_WRITE 0XD0 extern uint8_t MPU_Init(void); // 初始化MPU6050 extern float MPU_Get_Temperature(void); extern void MPU_Get_Gyroscope(short *gx, short *gy, short *gz); extern void MPU_Get_Accelerometer(short *ax, short *ay, short *az); extern void MPU_Deinit(void); #endif
YifuLiu/AliOS-Things
hardware/board/haaseduk1/drivers/sensor/drv_acc_gyro_inv_mpu6050.h
C
apache-2.0
4,862
/* * Copyright (C) 2015-2021 Alibaba Group Holding Limited */ #include "drv_acc_gyro_qst_qmi8610.h" #include "aos/kernel.h" #include "ulog/ulog.h" #include <math.h> #include <stdio.h> #include <stdlib.h> #define FIS210X_SLAVE_ADDR 0x6a #define FISIMU_UINT_MG_DPS enum { AXIS_X = 0, AXIS_Y = 1, AXIS_Z = 2, AXIS_TOTAL }; typedef struct { short sign[AXIS_TOTAL]; unsigned short map[AXIS_TOTAL]; } qst_imu_layout; static uint16_t acc_lsb_div = 0; static uint16_t gyro_lsb_div = 0; static struct FisImuConfig fisimu_config; uint8_t FisImu_write_reg(uint8_t reg, uint8_t value) { uint8_t ret = 0; #if defined(QST_USE_SPI) ret = qst_fis210x_spi_write(reg, value); #elif defined(QST_USE_SW_I2C) ret = qst_sw_writereg(FIS210X_SLAVE_ADDR, reg, value); #else uint8_t write_buf[2]; write_buf[0] = reg; write_buf[1] = value; sensor_i2c_master_send(1, FIS210X_SLAVE_ADDR, write_buf, 2, 1000); #endif return ret; } uint8_t FisImu_write_regs(uint8_t reg, uint8_t *value, uint8_t len) { uint8_t ret = 0; #if defined(QST_USE_SPI) ret = qst_fis210x_spi_write_bytes(reg, value, len); #elif defined(QST_USE_SW_I2C) ret = qst_sw_writeregs(FIS210X_SLAVE_ADDR, reg, value, len); #else sensor_i2c_mem_write(1, FIS210X_SLAVE_ADDR, reg, 1, &value, len, 100); #endif return ret; } uint8_t FisImu_read_reg(uint8_t reg, uint8_t *buf, uint16_t len) { uint8_t ret = 0; #if defined(QST_USE_SPI) ret = qst_fis210x_spi_read(reg, buf, len); #elif defined(QST_USE_SW_I2C) ret = qst_sw_readreg(FIS210X_SLAVE_ADDR, reg, buf, len); #else sensor_i2c_mem_read(1, FIS210X_SLAVE_ADDR, reg, 1, buf, len, 100); #endif return ret; } static qst_imu_layout imu_map; void FisImu_set_layout(short layout) { if (layout == 0) { imu_map.sign[AXIS_X] = 1; imu_map.sign[AXIS_Y] = 1; imu_map.sign[AXIS_Z] = 1; imu_map.map[AXIS_X] = AXIS_X; imu_map.map[AXIS_Y] = AXIS_Y; imu_map.map[AXIS_Z] = AXIS_Z; } else if (layout == 1) { imu_map.sign[AXIS_X] = -1; imu_map.sign[AXIS_Y] = 1; imu_map.sign[AXIS_Z] = 1; imu_map.map[AXIS_X] = AXIS_Y; imu_map.map[AXIS_Y] = AXIS_X; imu_map.map[AXIS_Z] = AXIS_Z; } else if (layout == 2) { imu_map.sign[AXIS_X] = -1; imu_map.sign[AXIS_Y] = -1; imu_map.sign[AXIS_Z] = 1; imu_map.map[AXIS_X] = AXIS_X; imu_map.map[AXIS_Y] = AXIS_Y; imu_map.map[AXIS_Z] = AXIS_Z; } else if (layout == 3) { imu_map.sign[AXIS_X] = 1; imu_map.sign[AXIS_Y] = -1; imu_map.sign[AXIS_Z] = 1; imu_map.map[AXIS_X] = AXIS_Y; imu_map.map[AXIS_Y] = AXIS_X; imu_map.map[AXIS_Z] = AXIS_Z; } else if (layout == 4) { imu_map.sign[AXIS_X] = -1; imu_map.sign[AXIS_Y] = 1; imu_map.sign[AXIS_Z] = -1; imu_map.map[AXIS_X] = AXIS_X; imu_map.map[AXIS_Y] = AXIS_Y; imu_map.map[AXIS_Z] = AXIS_Z; } else if (layout == 5) { imu_map.sign[AXIS_X] = 1; imu_map.sign[AXIS_Y] = 1; imu_map.sign[AXIS_Z] = -1; imu_map.map[AXIS_X] = AXIS_Y; imu_map.map[AXIS_Y] = AXIS_X; imu_map.map[AXIS_Z] = AXIS_Z; } else if (layout == 6) { imu_map.sign[AXIS_X] = 1; imu_map.sign[AXIS_Y] = -1; imu_map.sign[AXIS_Z] = -1; imu_map.map[AXIS_X] = AXIS_X; imu_map.map[AXIS_Y] = AXIS_Y; imu_map.map[AXIS_Z] = AXIS_Z; } else if (layout == 7) { imu_map.sign[AXIS_X] = -1; imu_map.sign[AXIS_Y] = -1; imu_map.sign[AXIS_Z] = -1; imu_map.map[AXIS_X] = AXIS_Y; imu_map.map[AXIS_Y] = AXIS_X; imu_map.map[AXIS_Z] = AXIS_Z; } else { imu_map.sign[AXIS_X] = 1; imu_map.sign[AXIS_Y] = 1; imu_map.sign[AXIS_Z] = 1; imu_map.map[AXIS_X] = AXIS_X; imu_map.map[AXIS_Y] = AXIS_Y; imu_map.map[AXIS_Z] = AXIS_Z; } } void FisImu_config_acc(enum FisImu_AccRange range, enum FisImu_AccOdr odr, enum FisImu_LpfConfig lpfEnable, enum FisImu_HpfConfig hpfEnable) { unsigned char ctl_dada; unsigned char range_set; switch (range) { case AccRange_2g: range_set = 0 << 3; acc_lsb_div = (1 << 14); break; case AccRange_4g: range_set = 1 << 3; acc_lsb_div = (1 << 13); break; case AccRange_8g: range_set = 2 << 3; acc_lsb_div = (1 << 12); break; default: range_set = 2 << 3; acc_lsb_div = (1 << 12); } ctl_dada = (unsigned char)range_set | (unsigned char)odr; FisImu_write_reg(FisRegister_Ctrl2, ctl_dada); // set LPF & HPF FisImu_read_reg(FisRegister_Ctrl5, &ctl_dada, 1); ctl_dada &= 0xfc; if (lpfEnable == Lpf_Enable) ctl_dada |= 0x02; if (hpfEnable == Hpf_Enable) ctl_dada |= 0x01; FisImu_write_reg(FisRegister_Ctrl5, ctl_dada); // set LPF & HPF } void FisImu_config_gyro(enum FisImu_GyrRange range, enum FisImu_GyrOdr odr, enum FisImu_LpfConfig lpfEnable, enum FisImu_HpfConfig hpfEnable) { // Set the CTRL3 register to configure dynamic range and ODR unsigned char ctl_dada; ctl_dada = (unsigned char)range | (unsigned char)odr; FisImu_write_reg(FisRegister_Ctrl3, ctl_dada); // Store the scale factor for use when processing raw data switch (range) { case GyrRange_32dps: gyro_lsb_div = 1024; break; case GyrRange_64dps: gyro_lsb_div = 512; break; case GyrRange_128dps: gyro_lsb_div = 256; break; case GyrRange_256dps: gyro_lsb_div = 128; break; case GyrRange_512dps: gyro_lsb_div = 64; break; case GyrRange_1024dps: gyro_lsb_div = 32; break; case GyrRange_2048dps: gyro_lsb_div = 16; break; case GyrRange_2560dps: // gyro_lsb_div = 8; break; default: gyro_lsb_div = 32; break; } // Conversion from degrees/s to rad/s if necessary // set LPF & HPF FisImu_read_reg(FisRegister_Ctrl5, &ctl_dada, 1); ctl_dada &= 0xf3; if (lpfEnable == Lpf_Enable) ctl_dada |= 0x08; if (hpfEnable == Hpf_Enable) ctl_dada |= 0x04; FisImu_write_reg(FisRegister_Ctrl5, ctl_dada); // set LPF & HPF } void FisImu_config_ae(enum FisImu_AeOdr odr) { // Configure Accelerometer and Gyroscope settings FisImu_config_acc(AccRange_8g, AccOdr_1024Hz, Lpf_Enable, Hpf_Disable); FisImu_config_gyro(GyrRange_2048dps, GyrOdr_1024Hz, Lpf_Enable, Hpf_Disable); FisImu_write_reg(FisRegister_Ctrl6, odr); } void FisImu_config_mag(enum FisImu_MagDev device, enum FisImu_MagOdr odr) { } uint8_t FisImu_readStatus0(void) { uint8_t status; FisImu_read_reg(FisRegister_Status0, &status, sizeof(status)); return status; } /*! * \brief Blocking read of data status register 1 (::FisRegister_Status1). * \returns Status byte \see STATUS1 for flag definitions. */ uint8_t FisImu_readStatus1(void) { uint8_t status; FisImu_read_reg(FisRegister_Status1, &status, sizeof(status)); return status; } int8_t FisImu_readTemp(void) { int8_t temp; FisImu_read_reg(FisRegister_Temperature, (uint8_t *)&temp, sizeof(temp)); return temp; } void FisImu_read_acc_xyz(float acc_xyz[3]) { unsigned char buf_reg[6]; short raw_acc_xyz[3]; #if defined(QST_USE_SPI) FisImu_read_reg(FisRegister_Ax_L, &buf_reg[0], 6); // 0x19, 25 #else FisImu_read_reg(FisRegister_Ax_L, &buf_reg[0], 1); // 0x19, 25 FisImu_read_reg(FisRegister_Ax_H, &buf_reg[1], 1); FisImu_read_reg(FisRegister_Ay_L, &buf_reg[2], 1); FisImu_read_reg(FisRegister_Ay_H, &buf_reg[3], 1); FisImu_read_reg(FisRegister_Az_L, &buf_reg[4], 1); FisImu_read_reg(FisRegister_Az_H, &buf_reg[5], 1); #endif raw_acc_xyz[0] = (short)((buf_reg[1] << 8) | (buf_reg[0])); raw_acc_xyz[1] = (short)((buf_reg[3] << 8) | (buf_reg[2])); raw_acc_xyz[2] = (short)((buf_reg[5] << 8) | (buf_reg[4])); // if(cali_flag == FALSE) // { // raw_acc_xyz[0]+=offset[0]; // raw_acc_xyz[1]+=offset[1]; // raw_acc_xyz[2]+=offset[2]; // } acc_xyz[0] = (raw_acc_xyz[0] * ONE_G) / acc_lsb_div; acc_xyz[1] = (raw_acc_xyz[1] * ONE_G) / acc_lsb_div; acc_xyz[2] = (raw_acc_xyz[2] * ONE_G) / acc_lsb_div; // acc_layout = 0; // acc_xyz[qst_map[acc_layout].map[0]] = qst_map[acc_layout].sign[0]*acc_xyz[0]; // acc_xyz[qst_map[acc_layout].map[1]] = qst_map[acc_layout].sign[1]*acc_xyz[1]; // acc_xyz[qst_map[acc_layout].map[2]] = qst_map[acc_layout].sign[2]*acc_xyz[2]; // LOGD("SENSOR", "fis210x acc: %f %f %f\n", acc_xyz[0], acc_xyz[1], acc_xyz[2]); } void FisImu_read_gyro_xyz(float gyro_xyz[3]) { unsigned char buf_reg[6]; short raw_gyro_xyz[3]; #if defined(QST_USE_SPI) FisImu_read_reg(FisRegister_Gx_L, &buf_reg[0], 6); // 0x19, 25 #else FisImu_read_reg(FisRegister_Gx_L, &buf_reg[0], 1); FisImu_read_reg(FisRegister_Gx_H, &buf_reg[1], 1); FisImu_read_reg(FisRegister_Gy_L, &buf_reg[2], 1); FisImu_read_reg(FisRegister_Gy_H, &buf_reg[3], 1); FisImu_read_reg(FisRegister_Gz_L, &buf_reg[4], 1); FisImu_read_reg(FisRegister_Gz_H, &buf_reg[5], 1); #endif raw_gyro_xyz[0] = (short)((buf_reg[1] << 8) | (buf_reg[0])); raw_gyro_xyz[1] = (short)((buf_reg[3] << 8) | (buf_reg[2])); raw_gyro_xyz[2] = (short)((buf_reg[5] << 8) | (buf_reg[4])); // if (cali_flag == FALSE) // { // raw_gyro_xyz[0] += offset_gyro[0]; // raw_gyro_xyz[1] += offset_gyro[1]; // raw_gyro_xyz[2] += offset_gyro[2]; // } gyro_xyz[0] = (raw_gyro_xyz[0] * 1.0f) / gyro_lsb_div; gyro_xyz[1] = (raw_gyro_xyz[1] * 1.0f) / gyro_lsb_div; gyro_xyz[2] = (raw_gyro_xyz[2] * 1.0f) / gyro_lsb_div; // acc_layout = 0; // gyro_xyz[qst_map[acc_layout].map[0]] = qst_map[acc_layout].sign[0]*gyro_xyz[0]; // gyro_xyz[qst_map[acc_layout].map[1]] = qst_map[acc_layout].sign[1]*gyro_xyz[1]; // gyro_xyz[qst_map[acc_layout].map[2]] = qst_map[acc_layout].sign[2]*gyro_xyz[2]; LOGD("SENSOR", "fis210x gyro: %f %f %f\n", gyro_xyz[0], gyro_xyz[1], gyro_xyz[2]); } void FisImu_read_xyz(float acc[3], float gyro[3]) { unsigned char buf_reg[12]; short raw_acc_xyz[3]; short raw_gyro_xyz[3]; float acc_t[3]; float gyro_t[3]; #if defined(QST_USE_SPI) if (tim_count) { FisImu_read_reg(FisRegister_CountOut, tim_count, 1); // 0x18 24 } FisImu_read_reg(FisRegister_Ax_L, &buf_reg[0], 12); // 0x19, 25 #else FisImu_read_reg(FisRegister_Ax_L | 0x80, buf_reg, 12); // 0x19, 25 #endif raw_acc_xyz[0] = (short)((buf_reg[1] << 8) | (buf_reg[0])); raw_acc_xyz[1] = (short)((buf_reg[3] << 8) | (buf_reg[2])); raw_acc_xyz[2] = (short)((buf_reg[5] << 8) | (buf_reg[4])); raw_gyro_xyz[0] = (short)((buf_reg[7] << 8) | (buf_reg[6])); raw_gyro_xyz[1] = (short)((buf_reg[9] << 8) | (buf_reg[8])); raw_gyro_xyz[2] = (short)((buf_reg[11] << 8) | (buf_reg[10])); // m/s2 acc_t[AXIS_X] = (float)(raw_acc_xyz[AXIS_X] * ONE_G) / acc_lsb_div; acc_t[AXIS_Y] = (float)(raw_acc_xyz[AXIS_Y] * ONE_G) / acc_lsb_div; acc_t[AXIS_Z] = (float)(raw_acc_xyz[AXIS_Z] * ONE_G) / acc_lsb_div; acc[AXIS_X] = -acc_t[AXIS_X]; // imu_map.sign[AXIS_X]*acc_t[imu_map.map[AXIS_X]]; acc[AXIS_Y] = -acc_t[AXIS_Y]; // imu_map.sign[AXIS_Y]*acc_t[imu_map.map[AXIS_Y]]; acc[AXIS_Z] = acc_t[AXIS_Z]; // imu_map.sign[AXIS_Z]*acc_t[imu_map.map[AXIS_Z]]; // rad/s gyro_t[AXIS_X] = (float)(raw_gyro_xyz[AXIS_X] * M_PI / 180) / gyro_lsb_div; // *pi/180 gyro_t[AXIS_Y] = (float)(raw_gyro_xyz[AXIS_Y] * M_PI / 180) / gyro_lsb_div; gyro_t[AXIS_Z] = (float)(raw_gyro_xyz[AXIS_Z] * M_PI / 180) / gyro_lsb_div; gyro[AXIS_X] = gyro_t[AXIS_X]; // imu_map.sign[AXIS_X]*gyro_t[imu_map.map[AXIS_X]]; gyro[AXIS_Y] = gyro_t[AXIS_Y]; // imu_map.sign[AXIS_Y]*gyro_t[imu_map.map[AXIS_Y]]; gyro[AXIS_Z] = -gyro_t[AXIS_Z]; // imu_map.sign[AXIS_Z]*gyro_t[imu_map.map[AXIS_Z]]; } // for XKF3 static inline void applyScaleFactor(float scaleFactor, uint8_t nElements, uint8_t const *rawData, float *calibratedData) { for (int i = 0; i < nElements; ++i) { calibratedData[i] = scaleFactor * (int16_t)((uint16_t)rawData[2 * i] | ((uint16_t)rawData[2 * i + 1] << 8)); } } void FisImu_processAccelerometerData(uint8_t const *rawData, float *calibratedData) { applyScaleFactor((float)(ONE_G / acc_lsb_div), 3, rawData, calibratedData); } void FisImu_processGyroscopeData(uint8_t const *rawData, float *calibratedData) { applyScaleFactor((float)(M_PI / (gyro_lsb_div * 180)), 3, rawData, calibratedData); } void FisImu_read_rawsample(struct FisImuRawSample *sample) { FisImu_read_reg(FisRegister_CountOut, &(sample->sampleCounter), sizeof(uint8_t)); sample->accelerometerData = sample->sampleBuffer; sample->gyroscopeData = sample->sampleBuffer + FISIMU_SAMPLE_SIZE; FisImu_read_reg(FisRegister_Ax_L, (uint8_t *)sample->accelerometerData, FISIMU_SAMPLE_SIZE); FisImu_read_reg(FisRegister_Gx_L, (uint8_t *)sample->gyroscopeData, FISIMU_SAMPLE_SIZE); } static void writeCalibrationVectorBuffer(float const *calVector, float conversionFactor, uint8_t fractionalBits) { int i; int16_t o; uint8_t calCmd[6]; // calCmd[0] = FisRegister_Cal1_L; for (i = 0; i < 3; ++i) { o = (int16_t)roundf(calVector[i] * conversionFactor * (1 << fractionalBits)); calCmd[(2 * i)] = o & 0xFF; calCmd[(2 * i) + 1] = o >> 8; } FisImu_write_regs(FisRegister_Cal1_L, calCmd, sizeof(calCmd)); } void FisImu_doCtrl9Command(enum FisImu_Ctrl9Command cmd) { uint8_t gyroConfig; const uint8_t oisModeBits = 0x06; unsigned char oisEnabled; uint8_t status = 0; uint32_t count = 0; FisImu_read_reg(FisRegister_Ctrl3, &gyroConfig, sizeof(gyroConfig)); oisEnabled = ((gyroConfig & oisModeBits) == oisModeBits); if (oisEnabled) { FisImu_write_reg(FisRegister_Ctrl3, (gyroConfig & ~oisModeBits)); } // g_fisDriverHal->waitForEvent(Fis_Int1, FisInt_low); // aos_msleep(300); FisImu_write_reg(FisRegister_Ctrl9, cmd); // g_fisDriverHal->waitForEvent(Fis_Int1, FisInt_high); // aos_msleep(300); // Check that command has been executed while (((status & FISIMU_STATUS1_CMD_DONE) == 0) && (count < 10000)) { FisImu_read_reg(FisRegister_Status1, &status, sizeof(status)); count++; } // assert(status & FISIMU_STATUS1_CMD_DONE); // g_fisDriverHal->waitForEvent(Fis_Int1, FisInt_low); // aos_msleep(300); if (oisEnabled) { // Re-enable OIS mode configuration if necessary FisImu_write_reg(FisRegister_Ctrl3, gyroConfig); } } void FisImu_applyAccelerometerOffset(float const *offset, enum FisImu_AccUnit unit) { const float conversionFactor = (unit == AccUnit_ms2) ? (1 / ONE_G) : 1; writeCalibrationVectorBuffer(offset, conversionFactor, 11); FisImu_doCtrl9Command(Ctrl9_SetAccelOffset); } void FisImu_applyGyroscopeOffset(float const *offset, enum FisImu_GyrUnit unit) { const float conversionFactor = (unit == GyrUnit_rads) ? 180 / M_PI : 1; writeCalibrationVectorBuffer(offset, conversionFactor, 6); FisImu_doCtrl9Command(Ctrl9_SetGyroOffset); } void FisImu_applyOffsetCalibration(struct FisImu_offsetCalibration const *cal) { FisImu_applyAccelerometerOffset(cal->accOffset, cal->accUnit); FisImu_applyGyroscopeOffset(cal->gyrOffset, cal->gyrUnit); } // for XKF3 void FisImu_enableWakeOnMotion(void) { uint8_t womCmd[3]; enum FisImu_Interrupt interrupt = Fis_Int1; enum FisImu_InterruptInitialState initialState = InterruptInitialState_low; enum FisImu_WakeOnMotionThreshold threshold = WomThreshold_low; uint8_t blankingTime = 0x00; const uint8_t blankingTimeMask = 0x3F; FisImu_enableSensors(FISIMU_CTRL7_DISABLE_ALL); // FisImu_config_acc(AccRange_2g, AccOdr_LowPower_3Hz, Lpf_Disable, Hpf_Disable); FisImu_config_acc(AccRange_2g, AccOdr_LowPower_25Hz, Lpf_Disable, Hpf_Disable); womCmd[0] = FisRegister_Cal1_L; // WoM Threshold: absolute value in mg (with 1mg/LSB resolution) womCmd[1] = threshold; womCmd[2] = (uint8_t)interrupt | (uint8_t)initialState | (blankingTime & blankingTimeMask); FisImu_write_reg(FisRegister_Cal1_L, womCmd[1]); FisImu_write_reg(FisRegister_Cal1_H, womCmd[2]); FisImu_doCtrl9Command(Ctrl9_ConfigureWakeOnMotion); FisImu_enableSensors(FISIMU_CTRL7_ACC_ENABLE); } void FisImu_disableWakeOnMotion(void) { FisImu_enableSensors(FISIMU_CTRL7_DISABLE_ALL); FisImu_write_reg(FisRegister_Cal1_L, 0); FisImu_doCtrl9Command(Ctrl9_ConfigureWakeOnMotion); } void FisImu_enableSensors(uint8_t enableFlags) { if (enableFlags & FISIMU_CONFIG_AE_ENABLE) { enableFlags |= FISIMU_CTRL7_ACC_ENABLE | FISIMU_CTRL7_GYR_ENABLE; } FisImu_write_reg(FisRegister_Ctrl7, enableFlags & FISIMU_CTRL7_ENABLE_MASK); } void FisImu_Config_apply(struct FisImuConfig const *config) { uint8_t fisSensors = config->inputSelection; if (fisSensors & FISIMU_CONFIG_AE_ENABLE) { FisImu_config_ae(config->aeOdr); } else { if (config->inputSelection & FISIMU_CONFIG_ACC_ENABLE) { // FisImu_config_acc(config->accRange, config->accOdr, Lpf_Disable, Hpf_Disable); FisImu_config_acc(config->accRange, config->accOdr, Lpf_Enable, Hpf_Disable); } if (config->inputSelection & FISIMU_CONFIG_GYR_ENABLE) { // FisImu_config_gyro(config->gyrRange, config->gyrOdr, Lpf_Disable, Hpf_Disable); FisImu_config_gyro(config->gyrRange, config->gyrOdr, Lpf_Enable, Hpf_Disable); } } if (config->inputSelection & FISIMU_CONFIG_MAG_ENABLE) { FisImu_config_mag(config->magDev, config->magOdr); } FisImu_enableSensors(fisSensors); } uint8_t FisImu_init(void) { uint8_t chip_id = 0x00; int32_t ret = sensor_i2c_open(1, FIS210X_SLAVE_ADDR, I2C_BUS_BIT_RATES_100K, 0); if (ret) { LOGE("SENSOR", "sensor i2c open 0x%x:0x%x failed, ret:%d\n", 0x1, FIS210X_SLAVE_ADDR, ret); return 0; } FisImu_read_reg(FisRegister_WhoAmI, &chip_id, 1); aos_msleep(100); if (chip_id == 0xfc) { fisimu_config.inputSelection = FISIMU_CONFIG_ACCGYR_ENABLE; fisimu_config.accRange = AccRange_4g; fisimu_config.accOdr = AccOdr_128Hz; fisimu_config.gyrRange = GyrRange_1024dps; // GyrRange_1024dps; fisimu_config.gyrOdr = GyrOdr_256Hz; // GyrOdr_1024Hz; fisimu_config.magOdr = MagOdr_32Hz; fisimu_config.magDev = MagDev_AK8963; fisimu_config.aeOdr = AeOdr_32Hz; aos_msleep(100); FisImu_Config_apply(&fisimu_config); aos_msleep(100); FisImu_set_layout(2); } else { chip_id = 0; } return chip_id; } void FisImu_deinit(void) { int32_t ret = sensor_i2c_close(1); if (ret) { LOGE("SENSOR", "sensor i2c close failed, ret:%d\n", ret); } return; }
YifuLiu/AliOS-Things
hardware/board/haaseduk1/drivers/sensor/drv_acc_gyro_qst_qmi8610.c
C
apache-2.0
19,445
/* * Copyright (C) 2015-2021 Alibaba Group Holding Limited */ #ifndef FIS210X_H #define FIS210X_H #include "k_api.h" #include <math.h> #include <stdbool.h> #include "aos/hal/i2c.h" #include "hal_iomux_haas1000.h" #ifndef M_PI #define M_PI (3.14159265358979323846f) #endif #ifndef ONE_G #define ONE_G (9.80665f) #endif #define FISIMU_CTRL7_DISABLE_ALL (0x0) #define FISIMU_CTRL7_ACC_ENABLE (0x1) #define FISIMU_CTRL7_GYR_ENABLE (0x2) #define FISIMU_CTRL7_MAG_ENABLE (0x4) #define FISIMU_CTRL7_AE_ENABLE (0x8) #define FISIMU_CTRL7_ENABLE_MASK (0xF) #define FISIMU_CONFIG_ACC_ENABLE FISIMU_CTRL7_ACC_ENABLE #define FISIMU_CONFIG_GYR_ENABLE FISIMU_CTRL7_GYR_ENABLE #define FISIMU_CONFIG_MAG_ENABLE FISIMU_CTRL7_MAG_ENABLE #define FISIMU_CONFIG_AE_ENABLE FISIMU_CTRL7_AE_ENABLE #define FISIMU_CONFIG_ACCGYR_ENABLE (FISIMU_CONFIG_ACC_ENABLE | FISIMU_CONFIG_GYR_ENABLE) #define FISIMU_CONFIG_ACCGYRMAG_ENABLE (FISIMU_CONFIG_ACC_ENABLE | FISIMU_CONFIG_GYR_ENABLE | FISIMU_CONFIG_MAG_ENABLE) #define FISIMU_CONFIG_AEMAG_ENABLE (FISIMU_CONFIG_AE_ENABLE | FISIMU_CONFIG_MAG_ENABLE) #define FISIMU_STATUS1_CMD_DONE (0x01) #define FISIMU_STATUS1_WAKEUP_EVENT (0x04) enum FIS210xRegister { /*! \brief FIS device identifier register. */ FisRegister_WhoAmI = 0, // 0 /*! \brief FIS hardware revision register. */ FisRegister_Revision, // 1 /*! \brief General and power management modes. */ FisRegister_Ctrl1, // 2 /*! \brief Accelerometer control. */ FisRegister_Ctrl2, // 3 /*! \brief Gyroscope control. */ FisRegister_Ctrl3, // 4 /*! \brief Magnetometer control. */ FisRegister_Ctrl4, // 5 /*! \brief Data processing settings. */ FisRegister_Ctrl5, // 6 /*! \brief AttitudeEngine control. */ FisRegister_Ctrl6, // 7 /*! \brief Sensor enabled status. */ FisRegister_Ctrl7, // 8 /*! \brief Reserved - do not write. */ FisRegister_Ctrl8, // 9 /*! \brief Host command register. */ FisRegister_Ctrl9, /*! \brief Calibration register 1 least significant byte. */ FisRegister_Cal1_L, /*! \brief Calibration register 1 most significant byte. */ FisRegister_Cal1_H, /*! \brief Calibration register 2 least significant byte. */ FisRegister_Cal2_L, /*! \brief Calibration register 2 most significant byte. */ FisRegister_Cal2_H, /*! \brief Calibration register 3 least significant byte. */ FisRegister_Cal3_L, /*! \brief Calibration register 3 most significant byte. */ FisRegister_Cal3_H, /*! \brief Calibration register 4 least significant byte. */ FisRegister_Cal4_L, /*! \brief Calibration register 4 most significant byte. */ FisRegister_Cal4_H, /*! \brief FIFO control register. */ FisRegister_FifoCtrl, /*! \brief FIFO data register. */ FisRegister_FifoData, /*! \brief FIFO status register. */ FisRegister_FifoStatus, /*! \brief Output data overrun and availability. */ FisRegister_Status0, /*! \brief Miscellaneous status register. */ FisRegister_Status1, /*! \brief Sample counter. */ FisRegister_CountOut, /*! \brief Accelerometer X axis least significant byte. */ FisRegister_Ax_L, /*! \brief Accelerometer X axis most significant byte. */ FisRegister_Ax_H, /*! \brief Accelerometer Y axis least significant byte. */ FisRegister_Ay_L, /*! \brief Accelerometer Y axis most significant byte. */ FisRegister_Ay_H, /*! \brief Accelerometer Z axis least significant byte. */ FisRegister_Az_L, /*! \brief Accelerometer Z axis most significant byte. */ FisRegister_Az_H, /*! \brief Gyroscope X axis least significant byte. */ FisRegister_Gx_L, /*! \brief Gyroscope X axis most significant byte. */ FisRegister_Gx_H, /*! \brief Gyroscope Y axis least significant byte. */ FisRegister_Gy_L, /*! \brief Gyroscope Y axis most significant byte. */ FisRegister_Gy_H, /*! \brief Gyroscope Z axis least significant byte. */ FisRegister_Gz_L, /*! \brief Gyroscope Z axis most significant byte. */ FisRegister_Gz_H, /*! \brief Magnetometer X axis least significant byte. */ FisRegister_Mx_L, /*! \brief Magnetometer X axis most significant byte. */ FisRegister_Mx_H, /*! \brief Magnetometer Y axis least significant byte. */ FisRegister_My_L, /*! \brief Magnetometer Y axis most significant byte. */ FisRegister_My_H, /*! \brief Magnetometer Z axis least significant byte. */ FisRegister_Mz_L, /*! \brief Magnetometer Z axis most significant byte. */ FisRegister_Mz_H, /*! \brief Quaternion increment W least significant byte. */ FisRegister_Q1_L = 45, /*! \brief Quaternion increment W most significant byte. */ FisRegister_Q1_H, /*! \brief Quaternion increment X least significant byte. */ FisRegister_Q2_L, /*! \brief Quaternion increment X most significant byte. */ FisRegister_Q2_H, /*! \brief Quaternion increment Y least significant byte. */ FisRegister_Q3_L, /*! \brief Quaternion increment Y most significant byte. */ FisRegister_Q3_H, /*! \brief Quaternion increment Z least significant byte. */ FisRegister_Q4_L, /*! \brief Quaternion increment Z most significant byte. */ FisRegister_Q4_H, /*! \brief Velocity increment X least significant byte. */ FisRegister_Dvx_L, /*! \brief Velocity increment X most significant byte. */ FisRegister_Dvx_H, /*! \brief Velocity increment Y least significant byte. */ FisRegister_Dvy_L, /*! \brief Velocity increment Y most significant byte. */ FisRegister_Dvy_H, /*! \brief Velocity increment Z least significant byte. */ FisRegister_Dvz_L, /*! \brief Velocity increment Z most significant byte. */ FisRegister_Dvz_H, /*! \brief Temperature output. */ FisRegister_Temperature, /*! \brief AttitudeEngine clipping flags. */ FisRegister_AeClipping, /*! \brief AttitudeEngine overflow flags. */ FisRegister_AeOverflow, }; enum FisImu_Ctrl9Command { /*! \brief No operation. */ Ctrl9_Nop = 0, /*! \brief Reset FIFO. */ Ctrl9_ResetFifo = 0x2, /*! \brief Set magnetometer X calibration values. */ Ctrl9_SetMagXCalibration = 0x6, /*! \brief Set magnetometer Y calibration values. */ Ctrl9_SetMagYCalibration = 0x7, /*! \brief Set magnetometer Z calibration values. */ Ctrl9_SetMagZCalibration = 0x8, /*! \brief Set accelerometer offset correction value. */ Ctrl9_SetAccelOffset = 0x12, /*! \brief Set gyroscope offset correction value. */ Ctrl9_SetGyroOffset = 0x13, /*! \brief Set accelerometer sensitivity. */ Ctrl9_SetAccelSensitivity = 0x14, /*! \brief Set gyroscope sensitivity. */ Ctrl9_SetGyroSensitivity = 0x15, /*! \brief Update magnemoter bias compensation. */ Ctrl9_UpdateMagBias = 0xB, /*! \brief Trigger motion on demand sample. */ Ctrl9_TriggerMotionOnDemand = 0x0c, /*! \brief Update gyroscope bias compensation. */ Ctrl9_UpdateAttitudeEngineGyroBias = 0xE, /*! \brief Read frequency correction value. */ Ctrl9_ReadTrimmedFrequencyValue = 0x18, /*! \brief Prepare for FIFO read sequence. */ Ctrl9_ReadFifo = 0x0D, /*! \brief Set wake on motion parameters. */ Ctrl9_ConfigureWakeOnMotion = 0x19, }; enum FisImu_LpfConfig { Lpf_Disable, /*!< \brief Disable low pass filter. */ Lpf_Enable /*!< \brief Enable low pass filter. */ }; enum FisImu_HpfConfig { Hpf_Disable, /*!< \brief Disable high pass filter. */ Hpf_Enable /*!< \brief Enable high pass filter. */ }; enum FisImu_AccRange { AccRange_2g = 0 << 3, /*!< \brief +/- 2g range */ AccRange_4g = 1 << 3, /*!< \brief +/- 4g range */ AccRange_8g = 2 << 3, /*!< \brief +/- 8g range */ AccRange_16g = 3 << 3 /*!< \brief +/- 16g range */ }; enum FisImu_AccOdr { AccOdr_1024Hz = 0, /*!< \brief High resolution 1024Hz output rate. */ AccOdr_256Hz = 1, /*!< \brief High resolution 256Hz output rate. */ AccOdr_128Hz = 2, /*!< \brief High resolution 128Hz output rate. */ AccOdr_32Hz = 3, /*!< \brief High resolution 32Hz output rate. */ AccOdr_LowPower_128Hz = 4, /*!< \brief Low power 128Hz output rate. */ AccOdr_LowPower_64Hz = 5, /*!< \brief Low power 64Hz output rate. */ AccOdr_LowPower_25Hz = 6, /*!< \brief Low power 25Hz output rate. */ AccOdr_LowPower_3Hz = 7 /*!< \brief Low power 3Hz output rate. */ }; enum FisImu_GyrRange { GyrRange_32dps = 0 << 3, /*!< \brief +-32 degrees per second. */ GyrRange_64dps = 1 << 3, /*!< \brief +-64 degrees per second. */ GyrRange_128dps = 2 << 3, /*!< \brief +-128 degrees per second. */ GyrRange_256dps = 3 << 3, /*!< \brief +-256 degrees per second. */ GyrRange_512dps = 4 << 3, /*!< \brief +-512 degrees per second. */ GyrRange_1024dps = 5 << 3, /*!< \brief +-1024 degrees per second. */ GyrRange_2048dps = 6 << 3, /*!< \brief +-2048 degrees per second. */ GyrRange_2560dps = 7 << 3 /*!< \brief +-2560 degrees per second. */ }; /*! * \brief Gyroscope output rate configuration. */ enum FisImu_GyrOdr { GyrOdr_1024Hz = 0, /*!< \brief High resolution 1024Hz output rate. */ GyrOdr_256Hz = 1, /*!< \brief High resolution 256Hz output rate. */ GyrOdr_128Hz = 2, /*!< \brief High resolution 128Hz output rate. */ GyrOdr_32Hz = 3, /*!< \brief High resolution 32Hz output rate. */ GyrOdr_OIS_8192Hz = 6, /*!< \brief OIS Mode 8192Hz output rate. */ GyrOdr_OIS_LL_8192Hz = 7 /*!< \brief OIS LL Mode 8192Hz output rate. */ }; enum FisImu_AeOdr { AeOdr_1Hz = 0, /*!< \brief 1Hz output rate. */ AeOdr_2Hz = 1, /*!< \brief 2Hz output rate. */ AeOdr_4Hz = 2, /*!< \brief 4Hz output rate. */ AeOdr_8Hz = 3, /*!< \brief 8Hz output rate. */ AeOdr_16Hz = 4, /*!< \brief 16Hz output rate. */ AeOdr_32Hz = 5, /*!< \brief 32Hz output rate. */ AeOdr_64Hz = 6, /*!< \brief 64Hz output rate. */ /*! * \brief Motion on demand mode. * * In motion on demand mode the application can trigger AttitudeEngine * output samples as necessary. This allows the AttitudeEngine to be * synchronized with external data sources. * * When in Motion on Demand mode the application should request new data * by calling the FisImu_requestAttitudeEngineData() function. The * AttitudeEngine will respond with a data ready event (INT2) when the * data is available to be read. */ AeOdr_motionOnDemand = 128 }; enum FisImu_MagOdr { MagOdr_32Hz = 2 /*!< \brief 32Hz output rate. */ }; enum FisImu_MagDev { MagDev_AK8975 = (0 << 4), /*!< \brief AKM AK8975. */ MagDev_AK8963 = (1 << 4) /*!< \brief AKM AK8963. */ }; enum FisImu_AccUnit { AccUnit_g, /*!< \brief Accelerometer output in terms of g (9.81m/s^2). */ AccUnit_ms2 /*!< \brief Accelerometer output in terms of m/s^2. */ }; enum FisImu_GyrUnit { GyrUnit_dps, /*!< \brief Gyroscope output in degrees/s. */ GyrUnit_rads /*!< \brief Gyroscope output in rad/s. */ }; struct FisImuConfig { /*! \brief Sensor fusion input selection. */ uint8_t inputSelection; /*! \brief Accelerometer dynamic range configuration. */ enum FisImu_AccRange accRange; /*! \brief Accelerometer output rate. */ enum FisImu_AccOdr accOdr; /*! \brief Gyroscope dynamic range configuration. */ enum FisImu_GyrRange gyrRange; /*! \brief Gyroscope output rate. */ enum FisImu_GyrOdr gyrOdr; /*! \brief AttitudeEngine output rate. */ enum FisImu_AeOdr aeOdr; /*! * \brief Magnetometer output data rate. * * \remark This parameter is not used when using an external magnetometer. * In this case the external magnetometer is sampled at the FIS output * data rate, or at an integer divisor thereof such that the maximum * sample rate is not exceeded. */ enum FisImu_MagOdr magOdr; /*! * \brief Magnetometer device to use. * * \remark This parameter is not used when using an external magnetometer. */ enum FisImu_MagDev magDev; }; #define FISIMU_SAMPLE_SIZE (3 * sizeof(int16_t)) #define FISIMU_AE_SAMPLE_SIZE ((4 + 3 + 1) * sizeof(int16_t) + sizeof(uint8_t)) struct FisImuRawSample { /*! \brief The sample counter of the sample. */ uint8_t sampleCounter; /*! * \brief Pointer to accelerometer data in the sample buffer. * * \c NULL if no accelerometer data is available in the buffer. */ uint8_t const *accelerometerData; /*! * \brief Pointer to gyroscope data in the sample buffer. * * \c NULL if no gyroscope data is available in the buffer. */ uint8_t const *gyroscopeData; /*! * \brief Pointer to magnetometer data in the sample buffer. * * \c NULL if no magnetometer data is available in the buffer. */ uint8_t const *magnetometerData; /*! * \brief Pointer to AttitudeEngine data in the sample buffer. * * \c NULL if no AttitudeEngine data is available in the buffer. */ uint8_t const *attitudeEngineData; /*! \brief Raw sample buffer. */ uint8_t sampleBuffer[FISIMU_SAMPLE_SIZE + FISIMU_AE_SAMPLE_SIZE]; /*! \brief Contents of the FIS status 1 register. */ uint8_t status1; // uint8_t status0; // uint32_t durT; }; struct FisImu_offsetCalibration { enum FisImu_AccUnit accUnit; float accOffset[3]; enum FisImu_GyrUnit gyrUnit; float gyrOffset[3]; }; struct FisImu_sensitivityCalibration { float accSensitivity[3]; float gyrSensitivity[3]; }; enum FisImu_Interrupt { /*! \brief FIS INT1 line. */ Fis_Int1 = (0 << 6), /*! \brief FIS INT2 line. */ Fis_Int2 = (1 << 6) }; enum FisImu_InterruptInitialState { InterruptInitialState_high = (1 << 7), /*!< Interrupt high. */ InterruptInitialState_low = (0 << 7) /*!< Interrupt low. */ }; enum FisImu_WakeOnMotionThreshold { WomThreshold_high = 128, /*!< High threshold - large motion needed to wake. */ WomThreshold_low = 32 /*!< Low threshold - small motion needed to wake. */ }; extern uint8_t FisImu_write_reg(uint8_t reg, uint8_t value); extern uint8_t FisImu_read_reg(uint8_t reg, uint8_t *buf, uint16_t len); extern uint8_t FisImu_init(void); extern void FisImu_deinit(void); extern void FisImu_Config_apply(struct FisImuConfig const *config); extern void FisImu_enableSensors(uint8_t enableFlags); extern void FisImu_read_acc_xyz(float acc_xyz[3]); extern void FisImu_read_gyro_xyz(float gyro_xyz[3]); extern void FisImu_read_xyz(float acc[3], float gyro[3]); extern uint8_t FisImu_readStatus1(void); extern int8_t FisImu_readTemp(void); extern void FisImu_enableWakeOnMotion(void); extern void FisImu_disableWakeOnMotion(void); // for XKF3 extern void FisImu_processAccelerometerData(uint8_t const *rawData, float *calibratedData); extern void FisImu_processGyroscopeData(uint8_t const *rawData, float *calibratedData); extern void FisImu_read_rawsample(struct FisImuRawSample *sample); extern void FisImu_applyOffsetCalibration(struct FisImu_offsetCalibration const *cal); // for XKF3 // fis210x #endif
YifuLiu/AliOS-Things
hardware/board/haaseduk1/drivers/sensor/drv_acc_gyro_qst_qmi8610.h
C
apache-2.0
15,351
/* * Copyright (C) 2015-2020 Alibaba Group Holding Limited */ #include "drv_als_ps_ir_liteon_ap3216c.h" #include "ulog/ulog.h" #include <aos/kernel.h> static i2c_dev_t i2c_dev; #define PKG_USING_AP3216C #ifdef PKG_USING_AP3216C #define AP3216C_I2C_PORT 1 #define AP3216C_ADDR 0x1e // System Register #define AP3216C_SYS_CONFIGURATION_REG 0x00 #define AP3216C_SYS_INT_STATUS_REG 0x01 #define AP3216C_SYS_INT_CLEAR_MANNER_REG 0x02 #define AP3216C_IR_DATA_L_REG 0x0A #define AP3216C_IR_DATA_H_REG 0x0B #define AP3216C_ALS_DATA_L_REG 0x0C #define AP3216C_ALS_DATA_H_REG 0x0D #define AP3216C_PS_DATA_L_REG 0x0E #define AP3216C_PS_DATA_H_REG 0x0F // ALS Register #define AP3216C_ALS_CONFIGURATION_REG 0x10 #define AP3216C_ALS_CALIBRATION_REG 0x19 #define AP3216C_ALS_THRESHOLD_LOW_L_REG 0x1A #define AP3216C_ALS_THRESHOLD_LOW_H_REG 0x1B #define AP3216C_ALS_THRESHOLD_HIGH_L_REG 0x1C #define AP3216C_ALS_THRESHOLD_HIGH_H_REG 0x1D // PS Register #define AP3216C_PS_CONFIGURATION_REG 0x20 #define AP3216C_PS_LED_DRIVER_REG 0x21 #define AP3216C_PS_INT_FORM_REG 0x22 #define AP3216C_PS_MEAN_TIME_REG 0x23 #define AP3216C_PS_LED_WAITING_TIME_REG 0x24 #define AP3216C_PS_CALIBRATION_L_REG 0x28 #define AP3216C_PS_CALIBRATION_H_REG 0x29 #define AP3216C_PS_THRESHOLD_LOW_L_REG 0x2A #define AP3216C_PS_THRESHOLD_LOW_H_REG 0x2B #define AP3216C_PS_THRESHOLD_HIGH_L_REG 0x2C #define AP3216C_PS_THRESHOLD_HIGH_H_REG 0x2D /* 写寄存器的值 */ static void write_reg(uint8_t reg, uint8_t data) { sensor_i2c_mem_write(AP3216C_I2C_PORT, AP3216C_ADDR, reg, 1, &data, 1, 100); } /* 读寄存器的值 */ static void read_regs(uint8_t reg, uint8_t len, uint8_t *buf) { sensor_i2c_mem_read(AP3216C_I2C_PORT, AP3216C_ADDR, reg, 1, buf, len, 100); } /* 软件复位传感器 */ static void reset_sensor(void) { write_reg(AP3216C_SYS_CONFIGURATION_REG, AP3216C_MODE_SW_RESET); // reset } /** * This function is convenient to getting data except including high and low * data for this sensor. note:after reading lower register first,reading higher * add one. */ static uint32_t read_low_and_high(uint8_t reg, uint8_t len) { uint32_t data; uint8_t buf = 0; read_regs(reg, len, &buf); // 读低字节 data = buf; read_regs(reg + 1, len, &buf); // 读高字节 data = data + (buf << len * 8); // 合并数据 return data; } /** * This function is only used to set threshold without filtering times * * @param cmd first register , and other cmd count by it. * @param threshold threshold and filtering times of als threshold */ static void set_als_threshold(ap3216c_cmd_t cmd, ap3216c_threshold_t threshold) { uint8_t Resolution; double DB = 1.0; /* 读光照强度的范围 */ ap3216c_get_param(AP3216C_ALS_RANGE, &Resolution); if (Resolution == AP3216C_ALS_RANGE_20661) { // 光照强度范围 0 - 20661 DB = 0.35; // 光照强度的分辨率 } else if (Resolution == AP3216C_ALS_RANGE_5162) { // 光照强度范围 0 - 5162 DB = 0.0788; // 光照强度的分辨率 } else if (Resolution == AP3216C_ALS_RANGE_1291) { // 光照强度范围 0 - 1291 DB = 0.0197; // 光照强度的分辨率 } else if (Resolution == AP3216C_ALS_RANGE_323) { // 光照强度范围 0 - 323 DB = 0.0049; // 光照强度的分辨率 } threshold.min /= DB; // 根据不同的分辨率来设置 threshold.max /= DB; ap3216c_set_param(cmd, (threshold.min & 0xff)); ap3216c_set_param((ap3216c_cmd_t)(cmd + 1), (threshold.min >> 8)); ap3216c_set_param((ap3216c_cmd_t)(cmd + 2), (threshold.max & 0xff)); ap3216c_set_param((ap3216c_cmd_t)(cmd + 3), threshold.max >> 8); } static void set_ps_threshold(ap3216c_cmd_t cmd, ap3216c_threshold_t threshold) { if (threshold.min > 1020) { // 大于1020 时需要设置低字节的低两位 ap3216c_set_param(cmd, (threshold.min - 1020 & 0x03)); } ap3216c_set_param((ap3216c_cmd_t)(cmd + 1), threshold.min / 4); // 设置高字节参数 if (threshold.max > 1020) { // 大于1020 时需要设置低字节的低两位 ap3216c_set_param((ap3216c_cmd_t)(cmd + 2), (threshold.max - 1020 & 0x03)); } ap3216c_set_param((ap3216c_cmd_t)(cmd + 3), threshold.max / 4); // 设置高字节参数 } /** * This function reads status register by ap3216c sensor measurement * * @param no * * @return status register value. */ uint8_t ap3216c_get_IntStatus(void) { uint8_t IntStatus; /* 读中断状态寄存器 */ read_regs(AP3216C_SYS_INT_STATUS_REG, 1, &IntStatus); // IntStatus 第 0 位表示 ALS 中断,第 1 位表示 PS 中断。 return IntStatus; // 返回状态 } static void ap3216c_int_init(void) { ; } /** * @brief 配置 中断输入引脚 * @param 无 * @retval 无 */ void ap3216c_int_Config(void) { ; } /** * This function initializes ap3216c registered device driver * * @param no * * @return the ap3216c device. */ void ap3216c_init(void) { int32_t ret = sensor_i2c_open(AP3216C_I2C_PORT, AP3216C_ADDR, I2C_BUS_BIT_RATES_100K, 0); if (ret) { LOGI("SENSOR", "sensor i2c open failed, ret:%d\n", ret); return; } /* reset ap3216c */ reset_sensor(); aos_msleep(100); ap3216c_set_param(AP3216C_SYSTEM_MODE, AP3216C_MODE_ALS_AND_PS); aos_msleep(150); // delay at least 112.5ms ap3216c_int_Config(); ap3216c_int_init(); } void ap3216c_deinit(void) { int32_t ret = sensor_i2c_close(AP3216C_I2C_PORT); if (ret) { LOGE("SENSOR", "sensor i2c close failed, ret:%d\n", ret); } return; } /** * This function reads light by ap3216c sensor measurement * * @param no * * @return the ambient light converted to float data. */ uint16_t ap3216c_read_ambient_light(void) { uint16_t brightness = 0; // default error data uint16_t read_data; uint8_t range; read_data = (uint16_t)read_low_and_high(AP3216C_ALS_DATA_L_REG, 1); ap3216c_get_param(AP3216C_ALS_RANGE, &range); if (range == AP3216C_ALS_RANGE_20661) { brightness = 0.35 * read_data; // sensor ambient light converse to reality } else if (range == AP3216C_ALS_RANGE_5162) { brightness = 0.0788 * read_data; // sensor ambient light converse to reality } else if (range == AP3216C_ALS_RANGE_1291) { brightness = 0.0197 * read_data; // sensor ambient light converse to reality } else if (range == AP3216C_ALS_RANGE_323) { brightness = 0.0049 * read_data; // sensor ambient light converse to reality } return brightness; } /** * This function reads proximity by ap3216c sensor measurement * * @param no * * @return the proximity data. */ uint16_t ap3216c_read_ps_data(void) { uint16_t proximity = 0; uint32_t read_data; read_data = read_low_and_high(AP3216C_PS_DATA_L_REG, 1); // read two data // printf("ap3216c_read_ps_data read_data %d\n",read_data); if (1 == ((read_data >> 6) & 0x01 || (read_data >> 14) & 0x01)) { return proximity = 55555; // 红外过高(IR),PS无效 返回一个 55555 的无效数据 } proximity = (read_data & 0x000f) + (((read_data >> 8) & 0x3f) << 4); // sensor proximity converse to reality proximity |= read_data & 0x8000; // 取最高位,0 表示物体远离,1 表示物体靠近 return proximity; // proximity 后十位是数据位,最高位为状态位 } /** * This function reads ir by ap3216c sensor measurement * * @param no * * @return the ir data. */ uint16_t ap3216c_read_ir_data(void) { uint16_t proximity = 0; uint32_t read_data; read_data = read_low_and_high(AP3216C_IR_DATA_L_REG, 1); // read two data // printf("ap3216c_read_ir_data read_data %d\n",read_data); proximity = (read_data & 0x0003) + ((read_data >> 8) & 0xFF); // sensor proximity converse to reality return proximity; } /** * This function sets parameter of ap3216c sensor * * @param cmd the parameter cmd of device * @param value for setting value in cmd register * * @return the setting parameter status,RT_EOK reprensents setting successfully. */ void ap3216c_set_param(ap3216c_cmd_t cmd, uint8_t value) { switch (cmd) { case AP3216C_SYSTEM_MODE: { /* default 000,power down */ write_reg(AP3216C_SYS_CONFIGURATION_REG, value); break; } case AP3216C_INT_PARAM: { write_reg(AP3216C_SYS_INT_CLEAR_MANNER_REG, value); break; } case AP3216C_ALS_RANGE: { uint8_t args; read_regs(AP3216C_ALS_CONFIGURATION_REG, 1, &args); args &= 0xcf; args |= value << 4; write_reg(AP3216C_ALS_CONFIGURATION_REG, args); break; } case AP3216C_ALS_PERSIST: { uint8_t args = 0; read_regs(AP3216C_ALS_CONFIGURATION_REG, 1, &args); args &= 0xf0; args |= value; write_reg(AP3216C_ALS_CONFIGURATION_REG, args); break; } case AP3216C_ALS_LOW_THRESHOLD_L: { write_reg(AP3216C_ALS_THRESHOLD_LOW_L_REG, value); break; } case AP3216C_ALS_LOW_THRESHOLD_H: { write_reg(AP3216C_ALS_THRESHOLD_LOW_H_REG, value); break; } case AP3216C_ALS_HIGH_THRESHOLD_L: { write_reg(AP3216C_ALS_THRESHOLD_HIGH_L_REG, value); break; } case AP3216C_ALS_HIGH_THRESHOLD_H: { write_reg(AP3216C_ALS_THRESHOLD_HIGH_H_REG, value); break; } case AP3216C_PS_GAIN: { uint8_t args = 0; read_regs(AP3216C_PS_CONFIGURATION_REG, 1, &args); args &= 0xf3; args |= value; write_reg(AP3216C_PS_CONFIGURATION_REG, args); break; } case AP3216C_PS_PERSIST: { uint8_t args = 0; read_regs(AP3216C_PS_CONFIGURATION_REG, 1, &args); args &= 0xfc; args |= value; write_reg(AP3216C_PS_CONFIGURATION_REG, args); break; } case AP3216C_PS_LOW_THRESHOLD_L: { write_reg(AP3216C_PS_THRESHOLD_LOW_L_REG, value); break; } case AP3216C_PS_LOW_THRESHOLD_H: { write_reg(AP3216C_PS_THRESHOLD_LOW_H_REG, value); break; } case AP3216C_PS_HIGH_THRESHOLD_L: { write_reg(AP3216C_PS_THRESHOLD_HIGH_L_REG, value); break; } case AP3216C_PS_HIGH_THRESHOLD_H: { write_reg(AP3216C_PS_THRESHOLD_HIGH_H_REG, value); break; } default: { break; } } } /** * This function gets parameter of ap3216c sensor * * @param cmd the parameter cmd of device * @param value to get value in cmd register * * @return the getting parameter status,RT_EOK reprensents getting successfully. */ void ap3216c_get_param(ap3216c_cmd_t cmd, uint8_t *value) { switch (cmd) { case AP3216C_SYSTEM_MODE: { read_regs(AP3216C_SYS_CONFIGURATION_REG, 1, value); break; } case AP3216C_INT_PARAM: { read_regs(AP3216C_SYS_INT_CLEAR_MANNER_REG, 1, value); break; } case AP3216C_ALS_RANGE: { uint8_t temp; read_regs(AP3216C_ALS_CONFIGURATION_REG, 1, value); temp = (*value & 0xff) >> 4; *value = temp; break; } case AP3216C_ALS_PERSIST: { uint8_t temp; read_regs(AP3216C_ALS_CONFIGURATION_REG, 1, value); temp = *value & 0x0f; *value = temp; break; } case AP3216C_ALS_LOW_THRESHOLD_L: { read_regs(AP3216C_ALS_THRESHOLD_LOW_L_REG, 1, value); break; } case AP3216C_ALS_LOW_THRESHOLD_H: { read_regs(AP3216C_ALS_THRESHOLD_LOW_H_REG, 1, value); break; } case AP3216C_ALS_HIGH_THRESHOLD_L: { read_regs(AP3216C_ALS_THRESHOLD_HIGH_L_REG, 1, value); break; } case AP3216C_ALS_HIGH_THRESHOLD_H: { read_regs(AP3216C_ALS_THRESHOLD_HIGH_H_REG, 1, value); break; } case AP3216C_PS_GAIN: { uint8_t temp; read_regs(AP3216C_PS_CONFIGURATION_REG, 1, &temp); *value = (temp & 0xc) >> 2; break; } case AP3216C_PS_PERSIST: { uint8_t temp; read_regs(AP3216C_PS_CONFIGURATION_REG, 1, &temp); *value = temp & 0x3; break; } case AP3216C_PS_LOW_THRESHOLD_L: { read_regs(AP3216C_PS_THRESHOLD_LOW_L_REG, 1, value); break; } case AP3216C_PS_LOW_THRESHOLD_H: { read_regs(AP3216C_PS_THRESHOLD_LOW_H_REG, 1, value); break; } case AP3216C_PS_HIGH_THRESHOLD_L: { read_regs(AP3216C_PS_THRESHOLD_HIGH_L_REG, 1, value); break; } case AP3216C_PS_HIGH_THRESHOLD_H: { read_regs(AP3216C_PS_THRESHOLD_HIGH_H_REG, 1, value); break; } default: { break; } } } #endif /* PKG_USING_AP3216C */
YifuLiu/AliOS-Things
hardware/board/haaseduk1/drivers/sensor/drv_als_ps_ir_liteon_ap3216c.c
C
apache-2.0
13,923
/* * Copyright (C) 2015-2020 Alibaba Group Holding Limited */ #ifndef __DRV_AP3216C_H__ #define __DRV_AP3216C_H__ #include "aos/hal/i2c.h" #include "hal_iomux_haas1000.h" // 中断引脚定义 #define AP_INT_GPIO_PIN HAL_IOMUX_PIN_P3_7 #define AP_INT_Read() \ HAL_GPIO_ReadPin(AP_INT_GPIO_PORT, AP_INT_GPIO_PIN) // 读中断引脚的状态 void AP_INT_Config(void); enum ap3216c_mode_value { AP3216C_MODE_POWER_DOWN, // Power down (Default) AP3216C_MODE_ALS, // ALS function active AP3216C_MODE_PS, // PS+IR function active AP3216C_MODE_ALS_AND_PS, // ALS and PS+IR functions active AP3216C_MODE_SW_RESET, // SW reset AP3216C_MODE_ALS_ONCE, // ALS function once AP3216C_MODE_PS_ONCE, // PS+IR function once AP3216C_MODE_ALS_AND_PS_ONCE, // ALS and PS+IR functions once }; enum ap3216c_int_clear_manner { AP3216C_INT_CLEAR_MANNER_BY_READING, // INT is automatically cleared by // reading data registers(Default) AP3216C_ALS_CLEAR_MANNER_BY_SOFTWARE, // Software clear after writing 1 into // address 0x01 each bit }; enum als_range { AP3216C_ALS_RANGE_20661, // Resolution = 0.35 lux/count(default). AP3216C_ALS_RANGE_5162, // Resolution = 0.0788 lux/count. AP3216C_ALS_RANGE_1291, // Resolution = 0.0197 lux/count. AP3216C_ALS_RANGE_323, // Resolution = 0.0049 lux/count }; typedef enum als_range als_range_t; enum ps_gain { AP3216C_PS_GAIN1, // detection distance *1. AP3216C_PS_GAIN2, // detection distance *2 (default). AP3216C_PS_GAIN4, // detection distance *4. AP3216C_PS_GAIN8, // detection distance *8. }; typedef enum als_gain ps_gain_t; enum ap3216c_cmd { AP3216C_SYSTEM_MODE, // system Configuration(Default : 000) AP3216C_INT_PARAM, // INT Clear Manner(Default : 0) AP3216C_ALS_RANGE, // ALS dynamic range(Default : 00) AP3216C_ALS_PERSIST, // ALS persist(Default : 0000) AP3216C_ALS_CALIBRATION, // ALS window loss calibration(Default : 0x40) AP3216C_ALS_LOW_THRESHOLD_L, // Lower byte of low interrupt threshold for // ALS(Default : 0x00) AP3216C_ALS_LOW_THRESHOLD_H, // Higher byte of low interrupt threshold for // ALS(Default : 0x00) AP3216C_ALS_HIGH_THRESHOLD_L, // Lower byte of high interrupt threshold for // ALS (Default : 0xFF) AP3216C_ALS_HIGH_THRESHOLD_H, // Higher byte of high interrupt threshold for // ALS(Default : 0xFF) AP3216C_PS_INTEGRATED_TIME, // PS or IR Integrated time select(Default : // 0000) AP3216C_PS_GAIN, // PS gain (Default : 01) AP3216C_PS_PERSIST, // Interrupt filter(Default : 01) AP3216C_PS_LED_CONTROL, // LED pulse(Default : 01) AP3216C_PS_LED_DRIVER_RATIO, // LED driver ratio(Default : 11) AP3216C_PS_INT_MODE, // PS INT Mode(Default : 0x01) AP3216C_PS_MEAN_TIME, // PS mean time(Default : 0x00) AP3216C_PS_WAITING_TIME, // PS LED Waiting(Default : 0x00) AP3216C_PS_CALIBRATION_L, // PS Calibration L(Default : 0x00) AP3216C_PS_CALIBRATION_H, // PS Calibration H(Default : 0x00) AP3216C_PS_LOW_THRESHOLD_L, // PS Low Threshold L(Default :0x00) AP3216C_PS_LOW_THRESHOLD_H, // PS Low Threshold H(Default :0x00) AP3216C_PS_HIGH_THRESHOLD_L, // PS high Threshold L(Default :0xff) AP3216C_PS_HIGH_THRESHOLD_H, // PS high Threshold H(Default :0xff) }; typedef enum ap3216c_cmd ap3216c_cmd_t; /* intrrupt parameters of ap3216c on ps or als */ struct ap3216c_threshold { uint16_t min; /* als 16 bits, ps 10 bits available(low byte :0-1 bit and High Byte :8-15 bit ) */ uint16_t max; /* als 16 bits, ps 10 bits available(low byte :0-1 bit and High Byte :8-15 bit ) */ uint8_t noises_time; /* filter special noises trigger interrupt */ }; typedef struct ap3216c_threshold ap3216c_threshold_t; uint8_t ap3216c_get_IntStatus(void); /** * This function initializes ap3216c registered device driver * * @param no * * @return no */ void ap3216c_init(void); /** * This function reads temperature by ap3216c sensor measurement * * @param no * * @return the ambient light converted to float data. */ uint16_t ap3216c_read_ambient_light(void); /** * This function reads temperature by ap3216c sensor measurement * * @param no * * @return the proximity data. */ uint16_t ap3216c_read_ps_data(void); uint16_t ap3216c_read_ir_data(void); /** * This function sets parameter of ap3216c sensor * * @param cmd the parameter cmd of device * @param value for setting value in cmd register * * @return the setting parameter status,RT_EOK reprensents setting successfully. */ void ap3216c_set_param(ap3216c_cmd_t cmd, uint8_t value); /** * This function gets parameter of ap3216c sensor * * @param cmd the parameter cmd of device * @param value to get value in cmd register * * @return the getting parameter status,RT_EOK reprensents getting successfully. */ void ap3216c_get_param(ap3216c_cmd_t cmd, uint8_t *value); #endif /*__DRV_AP3216C_H__ */
YifuLiu/AliOS-Things
hardware/board/haaseduk1/drivers/sensor/drv_als_ps_ir_liteon_ap3216c.h
C
apache-2.0
5,195
/* * Copyright (C) 2015-2020 Alibaba Group Holding Limited */ #include "drv_baro_goertek_spl06.h" #include "aos/hal/i2c.h" #include "ulog/ulog.h" #include <stdio.h> #include <stdlib.h> #define SPL06_I2C_PORT 1 uint8_t EEPROM_CHIP_ADDRESS = 0x77; static void i2c_eeprom_write_uint8_t(uint8_t deviceaddress, uint8_t eeaddress, uint8_t data) { uint8_t write_buffer[2] = {eeaddress, data}; sensor_i2c_master_send(SPL06_I2C_PORT, EEPROM_CHIP_ADDRESS, write_buffer, 2, 1000); } static uint8_t i2c_eeprom_read_uint8_t(uint8_t deviceaddress, uint8_t eeaddress) { uint8_t data; sensor_i2c_master_send(SPL06_I2C_PORT, EEPROM_CHIP_ADDRESS, &eeaddress, 1, 1000); aos_msleep(2); sensor_i2c_master_recv(SPL06_I2C_PORT, EEPROM_CHIP_ADDRESS, &data, 1, 1000); return data; } static double get_altitude(double pressure, double seaLevelhPa) { if (seaLevelhPa >= 0.0 && seaLevelhPa <= 0.0) { return -1; } double altitude; pressure /= 100; altitude = 44330 * (1.0 - pow(pressure / seaLevelhPa, 0.1903)); return altitude; } static double get_temperature_scale_factor() { double k; uint8_t tmp_Byte; tmp_Byte = i2c_eeprom_read_uint8_t(EEPROM_CHIP_ADDRESS, 0X07); // MSB tmp_Byte = tmp_Byte & 0B00000111; // printf("tmp_Byte: %d\n", tmp_Byte); switch (tmp_Byte) { case 0B000: k = 524288.0; break; case 0B001: k = 1572864.0; break; case 0B010: k = 3670016.0; break; case 0B011: k = 7864320.0; break; case 0B100: k = 253952.0; break; case 0B101: k = 516096.0; break; case 0B110: k = 1040384.0; break; case 0B111: k = 2088960.0; break; default: break; } return k; } static double get_pressure_scale_factor() { double k; uint8_t tmp_Byte; tmp_Byte = i2c_eeprom_read_uint8_t(EEPROM_CHIP_ADDRESS, 0X06); // MSB // tmp_Byte = tmp_Byte >> 4; //Focus on bits 6-4 - measurement rate tmp_Byte = tmp_Byte & 0B00000111; // Focus on 2-0 oversampling rate // tmp_Byte = 0B011; // oversampling rate switch (tmp_Byte) { case 0B000: k = 524288.0; break; case 0B001: k = 1572864.0; break; case 0B010: k = 3670016.0; break; case 0B011: k = 7864320.0; break; case 0B100: k = 253952.0; break; case 0B101: k = 516096.0; break; case 0B110: k = 1040384.0; break; case 0B111: k = 2088960.0; break; default: break; } return k; } static int32_t get_traw() { int32_t tmp; uint8_t tmp_MSB, tmp_LSB, tmp_XLSB; tmp_MSB = i2c_eeprom_read_uint8_t(EEPROM_CHIP_ADDRESS, 0X03); // MSB tmp_LSB = i2c_eeprom_read_uint8_t(EEPROM_CHIP_ADDRESS, 0X04); // LSB tmp_XLSB = i2c_eeprom_read_uint8_t(EEPROM_CHIP_ADDRESS, 0X05); // XLSB tmp = (tmp_MSB << 8) | tmp_LSB; tmp = (tmp << 8) | tmp_XLSB; if (tmp & (1 << 23)) tmp = tmp | 0XFF000000; // Set left bits to one for 2's complement // conversion of negitive number return tmp; } static int32_t get_praw() { int32_t tmp; uint8_t tmp_MSB, tmp_LSB, tmp_XLSB; tmp_MSB = i2c_eeprom_read_uint8_t(EEPROM_CHIP_ADDRESS, 0X00); // MSB tmp_LSB = i2c_eeprom_read_uint8_t(EEPROM_CHIP_ADDRESS, 0X01); // LSB tmp_XLSB = i2c_eeprom_read_uint8_t(EEPROM_CHIP_ADDRESS, 0X02); // XLSB tmp = (tmp_MSB << 8) | tmp_LSB; tmp = (tmp << 8) | tmp_XLSB; if (tmp & (1 << 23)) tmp = tmp | 0XFF000000; // Set left bits to one for 2's complement // conversion of negitive number return tmp; } static int16_t get_c0() { int16_t tmp; uint8_t tmp_MSB, tmp_LSB; tmp_MSB = i2c_eeprom_read_uint8_t(EEPROM_CHIP_ADDRESS, 0X10); tmp_LSB = i2c_eeprom_read_uint8_t(EEPROM_CHIP_ADDRESS, 0X11); tmp_LSB = tmp_LSB >> 4; tmp = (tmp_MSB << 4) | tmp_LSB; if (tmp & (1 << 11)) // Check for 2's complement negative number tmp = tmp | 0XF000; // Set left bits to one for 2's complement // conversion of negitive number return tmp; } static int16_t get_c1() { int16_t tmp; uint8_t tmp_MSB, tmp_LSB; tmp_MSB = i2c_eeprom_read_uint8_t(EEPROM_CHIP_ADDRESS, 0X11); tmp_LSB = i2c_eeprom_read_uint8_t(EEPROM_CHIP_ADDRESS, 0X12); tmp_MSB = tmp_MSB & 0XF; tmp = (tmp_MSB << 8) | tmp_LSB; if (tmp & (1 << 11)) // Check for 2's complement negative number tmp = tmp | 0XF000; // Set left bits to one for 2's complement // conversion of negitive number return tmp; } static int32_t get_c00() { int32_t tmp; uint8_t tmp_MSB, tmp_LSB, tmp_XLSB; tmp_MSB = i2c_eeprom_read_uint8_t(EEPROM_CHIP_ADDRESS, 0X13); tmp_LSB = i2c_eeprom_read_uint8_t(EEPROM_CHIP_ADDRESS, 0X14); tmp_XLSB = i2c_eeprom_read_uint8_t(EEPROM_CHIP_ADDRESS, 0X15); tmp_XLSB = tmp_XLSB >> 4; tmp = (tmp_MSB << 8) | tmp_LSB; tmp = (tmp << 4) | tmp_XLSB; tmp = (uint32_t)tmp_MSB << 12 | (uint32_t)tmp_LSB << 4 | (uint32_t)tmp_XLSB >> 4; if (tmp & (1 << 19)) tmp = tmp | 0XFFF00000; // Set left bits to one for 2's complement // conversion of negitive number return tmp; } static int32_t get_c10() { int32_t tmp; uint8_t tmp_MSB, tmp_LSB, tmp_XLSB; tmp_MSB = i2c_eeprom_read_uint8_t(EEPROM_CHIP_ADDRESS, 0X15); // 4 bits tmp_LSB = i2c_eeprom_read_uint8_t(EEPROM_CHIP_ADDRESS, 0X16); // 8 bits tmp_XLSB = i2c_eeprom_read_uint8_t(EEPROM_CHIP_ADDRESS, 0X17); // 8 bits tmp_MSB = tmp_MSB & 0b00001111; tmp = (tmp_MSB << 4) | tmp_LSB; tmp = (tmp << 8) | tmp_XLSB; tmp = (uint32_t)tmp_MSB << 16 | (uint32_t)tmp_LSB << 8 | (uint32_t)tmp_XLSB; if (tmp & (1 << 19)) tmp = tmp | 0XFFF00000; // Set left bits to one for 2's complement // conversion of negitive number return tmp; } static int16_t get_c01() { int16_t tmp; uint8_t tmp_MSB, tmp_LSB; tmp_MSB = i2c_eeprom_read_uint8_t(EEPROM_CHIP_ADDRESS, 0X18); tmp_LSB = i2c_eeprom_read_uint8_t(EEPROM_CHIP_ADDRESS, 0X19); tmp = (tmp_MSB << 8) | tmp_LSB; return tmp; } static int16_t get_c11() { int16_t tmp; uint8_t tmp_MSB, tmp_LSB; tmp_MSB = i2c_eeprom_read_uint8_t(EEPROM_CHIP_ADDRESS, 0X1A); tmp_LSB = i2c_eeprom_read_uint8_t(EEPROM_CHIP_ADDRESS, 0X1B); tmp = (tmp_MSB << 8) | tmp_LSB; return tmp; } static int16_t get_c20() { int16_t tmp; uint8_t tmp_MSB, tmp_LSB; tmp_MSB = i2c_eeprom_read_uint8_t(EEPROM_CHIP_ADDRESS, 0X1C); tmp_LSB = i2c_eeprom_read_uint8_t(EEPROM_CHIP_ADDRESS, 0X1D); tmp = (tmp_MSB << 8) | tmp_LSB; return tmp; } static int16_t get_c21() { int16_t tmp; uint8_t tmp_MSB, tmp_LSB; tmp_MSB = i2c_eeprom_read_uint8_t(EEPROM_CHIP_ADDRESS, 0X1E); tmp_LSB = i2c_eeprom_read_uint8_t(EEPROM_CHIP_ADDRESS, 0X1F); tmp = (tmp_MSB << 8) | tmp_LSB; return tmp; } static int16_t get_c30() { int16_t tmp; uint8_t tmp_MSB, tmp_LSB; tmp_MSB = i2c_eeprom_read_uint8_t(EEPROM_CHIP_ADDRESS, 0X20); tmp_LSB = i2c_eeprom_read_uint8_t(EEPROM_CHIP_ADDRESS, 0X21); tmp = (tmp_MSB << 8) | tmp_LSB; return tmp; // printf("tmp: %d\n", tmp); } void spl06_init(void) { uint8_t tmp, data; int32_t ret = sensor_i2c_open(SPL06_I2C_PORT, EEPROM_CHIP_ADDRESS, I2C_BUS_BIT_RATES_100K, 0); if (ret) { LOGE("SENSOR", "sensor i2c open failed, ret:%d\n", ret); return; } aos_msleep(500); // printf("\nDevice Reset\n"); // i2c_eeprom_write_uint8_t(EEPROM_CHIP_ADDRESS, 0X0C, 0b1001); // aos_msleep(1000); tmp = i2c_eeprom_read_uint8_t(EEPROM_CHIP_ADDRESS, 0x0D); // printf("ID: %d\n", tmp); i2c_eeprom_write_uint8_t(EEPROM_CHIP_ADDRESS, 0X06, 0x03); // Pressure 8x oversampling i2c_eeprom_write_uint8_t(EEPROM_CHIP_ADDRESS, 0X07, 0X83); // Temperature 8x oversampling i2c_eeprom_write_uint8_t( EEPROM_CHIP_ADDRESS, 0X08, 0B0111); // continuous temp and pressure measurement // i2c_eeprom_write_uint8_t(EEPROM_CHIP_ADDRESS, 0X08, 0B0001); // standby // pressure measurement i2c_eeprom_write_uint8_t(EEPROM_CHIP_ADDRESS, 0X09, 0X00); // FIFO Pressure measurement } void spl06_getdata(spl06_data_t *sp) { uint8_t tmp; int32_t c00, c10; int16_t c0, c1, c01, c11, c20, c21, c30; // Serial.println("\nDevice Reset\n"); // i2c_eeprom_write_uint8_t(EEPROM_CHIP_ADDRESS, 0x0C, 0b1001); // delay(1000); tmp = i2c_eeprom_read_uint8_t(EEPROM_CHIP_ADDRESS, 0x0D); sp->id = tmp; tmp = i2c_eeprom_read_uint8_t(EEPROM_CHIP_ADDRESS, 0x06); tmp = i2c_eeprom_read_uint8_t(EEPROM_CHIP_ADDRESS, 0x07); tmp = i2c_eeprom_read_uint8_t(EEPROM_CHIP_ADDRESS, 0x08); tmp = i2c_eeprom_read_uint8_t(EEPROM_CHIP_ADDRESS, 0x09); tmp = i2c_eeprom_read_uint8_t(EEPROM_CHIP_ADDRESS, 0x0A); tmp = i2c_eeprom_read_uint8_t(EEPROM_CHIP_ADDRESS, 0x0B); c0 = get_c0(); c1 = get_c1(); c00 = get_c00(); c10 = get_c10(); c01 = get_c01(); c11 = get_c11(); c20 = get_c20(); c21 = get_c21(); c30 = get_c30(); int32_t traw = get_traw(); double traw_sc = (double)traw / get_temperature_scale_factor(); // printf("traw_sc: %0.2f\n", traw_sc); sp->Ctemp = (double)c0 * 0.5f + (double)c1 * traw_sc; sp->Ftemp = (sp->Ctemp * 9 / 5) + 32; int32_t praw = get_praw(); double praw_sc = (double)(praw) / get_pressure_scale_factor(); double pcomp = (double)(c00) + praw_sc * ((double)(c10) + praw_sc * ((double)(c20) + praw_sc * (double)(c30))) + traw_sc * (double)(c01) + traw_sc * praw_sc * ((double)(c11) + praw_sc * (double)(c21)); sp->pressure = pcomp / 100; // convert to mb // double local_pressure = 1010.5; // Look up local sea level pressure on // google double local_pressure = 1011.1; // Look up local sea level pressure on google // Local pressure // from airport website 8/22 // printf("Local Airport Sea Level Pressure: %0.2f mb\n", local_pressure); sp->altitude = get_altitude(pcomp, local_pressure); } void spl06_deinit(void) { int32_t ret = sensor_i2c_close(SPL06_I2C_PORT); if (ret) { LOGE("SENSOR", "sensor i2c close failed, ret:%d\n", ret); return; } }
YifuLiu/AliOS-Things
hardware/board/haaseduk1/drivers/sensor/drv_baro_goertek_spl06.c
C
apache-2.0
10,912
/* * Copyright (C) 2015-2020 Alibaba Group Holding Limited */ #include <stdio.h> #ifndef SENSOR_SPI06_H #define SENSOR_SPI06_H #ifdef __cplusplus extern "C" { #endif typedef struct { uint8_t id; double Ctemp; double Ftemp; double pressure; double altitude; } spl06_data_t; extern void spl06_init(void); extern void spl06_getdata(spl06_data_t *p); #ifdef __cplusplus } #endif #endif
YifuLiu/AliOS-Things
hardware/board/haaseduk1/drivers/sensor/drv_baro_goertek_spl06.h
C
apache-2.0
413
/* * Copyright (C) 2015-2021 Alibaba Group Holding Limited */ #include <math.h> #include "drv_baro_qst_qmp6988.h" #include "aos/hal/i2c.h" #include "ulog/ulog.h" #include <stdio.h> #include <stdlib.h> #define QMP6988_LOG #define QMP6988_ERR printf #if !defined(QMP6988_CALC_INT) static float const Conv_A_S[10][2] = { {-6.30E-03, 4.30E-04}, {-1.90E-11, 1.20E-10}, {1.00E-01, 9.10E-02}, {1.20E-08, 1.20E-06}, {3.30E-02, 1.90E-02}, {2.10E-07, 1.40E-07}, {-6.30E-10, 3.50E-10}, {2.90E-13, 7.60E-13}, {2.10E-15, 1.20E-14}, {1.30E-16, 7.90E-17}, }; #endif static void qmp6988_delay(unsigned int delay) { int i, j; for (i = 0; i < delay; i++) { for (j = 0; j < 1000; j++) { ; } } } uint8_t qmp6988_WriteReg(uint8_t slave, uint8_t reg_add, uint8_t reg_dat) { #if defined(QST_USE_SPI) return qmp6988_spi_write(reg_add, reg_dat); #elif defined(QST_USE_SW_I2C) return qst_sw_writereg(slave, reg_add, reg_dat); #else uint8_t write_buf[2]; write_buf[0] = reg_add; write_buf[1] = reg_dat; sensor_i2c_master_send(1, slave, write_buf, 2, 1000); return 1; #endif } uint8_t qmp6988_ReadData(uint8_t slave, uint8_t reg_add, unsigned char *Read, uint8_t num) { #if defined(QST_USE_SPI) return qmp6988_spi_read(reg_add, Read, num); #elif defined(QST_USE_SW_I2C) return qst_sw_readreg(slave, reg_add, Read, num); #else uint8_t data; sensor_i2c_master_send(1, slave, &reg_add, 1, 1000); aos_msleep(2); sensor_i2c_master_recv(1, slave, Read, num, 1000); return 1; #endif } static uint8_t qmp6988_device_check(qmp6988_data *qmp6988) { uint8_t slave_addr[1] = {QMP6988_SLAVE_ADDRESS_H}; uint8_t ret = 0; uint8_t i; for (i = 0; i < 1; i++) { qmp6988->slave = slave_addr[i]; ret = qmp6988_ReadData(qmp6988->slave, QMP6988_CHIP_ID_REG, &(qmp6988->chip_id), 1); if (ret == 0) { QMP6988_LOG("%s: read 0xD1 failed\n", __func__); continue; } QMP6988_LOG("qmp6988 read chip id = 0x%x\n", qmp6988->chip_id); if (qmp6988->chip_id == QMP6988_CHIP_ID) { return 1; } } return 0; } static int qmp6988_get_calibration_data(qmp6988_data *qmp6988) { int status = 0; // BITFIELDS temp_COE; uint8_t a_data_u8r[QMP6988_CALIBRATION_DATA_LENGTH] = {0}; int len; for (len = 0; len < QMP6988_CALIBRATION_DATA_LENGTH; len += 1) { // if((qmp6988_cali_data_LENGTH-len) >= 8 ) // status = qmp6988_ReadData(qmp6988_cali_data_START+len,&a_data_u8r[len],8); // else // status = qmp6988_ReadData(qmp6988_cali_data_START+len,&a_data_u8r[len],(qmp6988_cali_data_LENGTH-len)); status = qmp6988_ReadData(qmp6988->slave, QMP6988_CALIBRATION_DATA_START + len, &a_data_u8r[len], 1); if (status == 0) { QMP6988_LOG("qmp6988 read 0xA0 error!"); return status; } } qmp6988->qmp6988_cali.COE_a0 = (QMP6988_S32_t)(((a_data_u8r[18] << SHIFT_LEFT_12_POSITION) \ | (a_data_u8r[19] << SHIFT_LEFT_4_POSITION) \ | (a_data_u8r[24] & 0x0f)) << 12); qmp6988->qmp6988_cali.COE_a0 = qmp6988->qmp6988_cali.COE_a0 >> 12; qmp6988->qmp6988_cali.COE_a1 = (QMP6988_S16_t)(((a_data_u8r[20]) << SHIFT_LEFT_8_POSITION) | a_data_u8r[21]); qmp6988->qmp6988_cali.COE_a2 = (QMP6988_S16_t)(((a_data_u8r[22]) << SHIFT_LEFT_8_POSITION) | a_data_u8r[23]); qmp6988->qmp6988_cali.COE_b00 = (QMP6988_S32_t)(((a_data_u8r[0] << SHIFT_LEFT_12_POSITION) \ | (a_data_u8r[1] << SHIFT_LEFT_4_POSITION) \ | ((a_data_u8r[24] & 0xf0) >> SHIFT_RIGHT_4_POSITION)) << 12); qmp6988->qmp6988_cali.COE_b00 = qmp6988->qmp6988_cali.COE_b00 >> 12; qmp6988->qmp6988_cali.COE_bt1 = (QMP6988_S16_t)(((a_data_u8r[2]) << SHIFT_LEFT_8_POSITION) | a_data_u8r[3]); qmp6988->qmp6988_cali.COE_bt2 = (QMP6988_S16_t)(((a_data_u8r[4]) << SHIFT_LEFT_8_POSITION) | a_data_u8r[5]); qmp6988->qmp6988_cali.COE_bp1 = (QMP6988_S16_t)(((a_data_u8r[6]) << SHIFT_LEFT_8_POSITION) | a_data_u8r[7]); qmp6988->qmp6988_cali.COE_b11 = (QMP6988_S16_t)(((a_data_u8r[8]) << SHIFT_LEFT_8_POSITION) | a_data_u8r[9]); qmp6988->qmp6988_cali.COE_bp2 = (QMP6988_S16_t)(((a_data_u8r[10]) << SHIFT_LEFT_8_POSITION) | a_data_u8r[11]); qmp6988->qmp6988_cali.COE_b12 = (QMP6988_S16_t)(((a_data_u8r[12]) << SHIFT_LEFT_8_POSITION) | a_data_u8r[13]); qmp6988->qmp6988_cali.COE_b21 = (QMP6988_S16_t)(((a_data_u8r[14]) << SHIFT_LEFT_8_POSITION) | a_data_u8r[15]); qmp6988->qmp6988_cali.COE_bp3 = (QMP6988_S16_t)(((a_data_u8r[16]) << SHIFT_LEFT_8_POSITION) | a_data_u8r[17]); QMP6988_LOG("<-----------calibration data-------------->\n"); QMP6988_LOG("COE_a0[%d] COE_a1[%d] COE_a2[%d] COE_b00[%d]\n", \ qmp6988->qmp6988_cali.COE_a0, qmp6988->qmp6988_cali.COE_a1, qmp6988->qmp6988_cali.COE_a2, qmp6988->qmp6988_cali.COE_b00); QMP6988_LOG("COE_bt1[%d] COE_bt2[%d] COE_bp1[%d] COE_b11[%d]\n", \ qmp6988->qmp6988_cali.COE_bt1, qmp6988->qmp6988_cali.COE_bt2, qmp6988->qmp6988_cali.COE_bp1, qmp6988->qmp6988_cali.COE_b11); QMP6988_LOG("COE_bp2[%d] COE_b12[%d] COE_b21[%d] COE_bp3[%d]\n", \ qmp6988->qmp6988_cali.COE_bp2, qmp6988->qmp6988_cali.COE_b12, qmp6988->qmp6988_cali.COE_b21, qmp6988->qmp6988_cali.COE_bp3); QMP6988_LOG("<-----------calibration data-------------->\n"); #if defined(QMP6988_CALC_INT) qmp6988->ik.a0 = qmp6988->qmp6988_cali.COE_a0; // 20Q4 qmp6988->ik.b00 = qmp6988->qmp6988_cali.COE_b00; // 20Q4 qmp6988->ik.a1 = 3608L * (QMP6988_S32_t)qmp6988->qmp6988_cali.COE_a1 - 1731677965L; // 31Q23 qmp6988->ik.a2 = 16889L * (QMP6988_S32_t) qmp6988->qmp6988_cali.COE_a2 - 87619360L; // 30Q47 qmp6988->ik.bt1 = 2982L * (QMP6988_S64_t)qmp6988->qmp6988_cali.COE_bt1 + 107370906L; // 28Q15 qmp6988->ik.bt2 = 329854L * (QMP6988_S64_t)qmp6988->qmp6988_cali.COE_bt2 + 108083093L; // 34Q38 qmp6988->ik.bp1 = 19923L * (QMP6988_S64_t)qmp6988->qmp6988_cali.COE_bp1 + 1133836764L; // 31Q20 qmp6988->ik.b11 = 2406L * (QMP6988_S64_t)qmp6988->qmp6988_cali.COE_b11 + 118215883L; // 28Q34 qmp6988->ik.bp2 = 3079L * (QMP6988_S64_t)qmp6988->qmp6988_cali.COE_bp2 - 181579595L; // 29Q43 qmp6988->ik.b12 = 6846L * (QMP6988_S64_t)qmp6988->qmp6988_cali.COE_b12 + 85590281L; // 29Q53 qmp6988->ik.b21 = 13836L * (QMP6988_S64_t)qmp6988->qmp6988_cali.COE_b21 + 79333336L; // 29Q60 qmp6988->ik.bp3 = 2915L * (QMP6988_S64_t)qmp6988->qmp6988_cali.COE_bp3 + 157155561L; // 28Q65 /* QMP6988_LOG("<----------- int calibration data -------------->\n"); QMP6988_LOG("a0[%d] a1[%d] a2[%d] b00[%d]\n", qmp6988->ik.a0, qmp6988->ik.a1, qmp6988->ik.a2, qmp6988->ik.b00); QMP6988_LOG("bt1[%lld] bt2[%lld] bp1[%lld] b11[%lld]\n", qmp6988->ik.bt1, qmp6988->ik.bt2, qmp6988->ik.bp1, qmp6988->ik.b11); QMP6988_LOG("bp2[%lld] b12[%lld] b21[%lld] bp3[%lld]\n", qmp6988->ik.bp2, qmp6988->ik.b12, qmp6988->ik.b21, qmp6988->ik.bp3); QMP6988_LOG("<----------- int calibration data -------------->\n"); */ #else qmp6988->fk.a0 = qmp6988->qmp6988_cali.COE_a0 / 16.0f; qmp6988->fk.b00 = qmp6988->qmp6988_cali.COE_b00 / 16.0f; qmp6988->fk.a1 = Conv_A_S[0][0] + Conv_A_S[0][1] * qmp6988->qmp6988_cali.COE_a1 / 32767.0f; qmp6988->fk.a2 = Conv_A_S[1][0] + Conv_A_S[1][1] * qmp6988->qmp6988_cali.COE_a2 / 32767.0f; qmp6988->fk.bt1 = Conv_A_S[2][0] + Conv_A_S[2][1] * qmp6988->qmp6988_cali.COE_bt1 / 32767.0f; qmp6988->fk.bt2 = Conv_A_S[3][0] + Conv_A_S[3][1] * qmp6988->qmp6988_cali.COE_bt2 / 32767.0f; qmp6988->fk.bp1 = Conv_A_S[4][0] + Conv_A_S[4][1] * qmp6988->qmp6988_cali.COE_bp1 / 32767.0f; qmp6988->fk.b11 = Conv_A_S[5][0] + Conv_A_S[5][1] * qmp6988->qmp6988_cali.COE_b11 / 32767.0f; qmp6988->fk.bp2 = Conv_A_S[6][0] + Conv_A_S[6][1] * qmp6988->qmp6988_cali.COE_bp2 / 32767.0f; qmp6988->fk.b12 = Conv_A_S[7][0] + Conv_A_S[7][1] * qmp6988->qmp6988_cali.COE_b12 / 32767.0f; qmp6988->fk.b21 = Conv_A_S[8][0] + Conv_A_S[8][1] * qmp6988->qmp6988_cali.COE_b21 / 32767.0f; qmp6988->fk.bp3 = Conv_A_S[9][0] + Conv_A_S[9][1] * qmp6988->qmp6988_cali.COE_bp3 / 32767.0f; /* QMP6988_LOG("<----------- float calibration data -------------->\n"); QMP6988_LOG("a0[%lle] a1[%lle] a2[%lle] b00[%lle]\n", qmp6988->fk.a0, qmp6988->fk.a1, qmp6988->fk.a2, qmp6988->fk.b00); QMP6988_LOG("bt1[%lle] bt2[%lle] bp1[%lle] b11[%lle]\n", qmp6988->fk.bt1, qmp6988->fk.bt2, qmp6988->fk.bp1, qmp6988->fk.b11); QMP6988_LOG("bp2[%lle] b12[%lle] b21[%lle] bp3[%lle]\n", qmp6988->fk.bp2, qmp6988->fk.b12, qmp6988->fk.b21, qmp6988->fk.bp3); QMP6988_LOG("<----------- float calibration data -------------->\n"); */ #endif return 1; } #if defined(QMP6988_CALC_INT) static QMP6988_S16_t qmp6988_convTx_02e(qmp6988_ik_data *ik, QMP6988_S32_t dt) { QMP6988_S16_t ret; QMP6988_S64_t wk1, wk2; // wk1: 60Q4 // bit size wk1 = ((QMP6988_S64_t)ik->a1 * (QMP6988_S64_t)dt); // 31Q23+24-1=54 (54Q23) wk2 = ((QMP6988_S64_t)ik->a2 * (QMP6988_S64_t)dt) >> 14; // 30Q47+24-1=53 (39Q33) wk2 = (wk2 * (QMP6988_S64_t)dt) >> 10; // 39Q33+24-1=62 (52Q23) wk2 = ((wk1 + wk2) / 32767) >> 19; // 54,52->55Q23 (20Q04) ret = (QMP6988_S16_t)((ik->a0 + wk2) >> 4); // 21Q4 -> 17Q0 return ret; } static QMP6988_S32_t qmp6988_get_pressure_02e(qmp6988_ik_data *ik, QMP6988_S32_t dp, QMP6988_S16_t tx) { QMP6988_S32_t ret; QMP6988_S64_t wk1, wk2, wk3; // wk1 = 48Q16 // bit size wk1 = ((QMP6988_S64_t)ik->bt1 * (QMP6988_S64_t)tx); // 28Q15+16-1=43 (43Q15) wk2 = ((QMP6988_S64_t)ik->bp1 * (QMP6988_S64_t)dp) >> 5; // 31Q20+24-1=54 (49Q15) wk1 += wk2; // 43,49->50Q15 wk2 = ((QMP6988_S64_t)ik->bt2 * (QMP6988_S64_t)tx) >> 1; // 34Q38+16-1=49 (48Q37) wk2 = (wk2 * (QMP6988_S64_t)tx) >> 8; // 48Q37+16-1=63 (55Q29) wk3 = wk2; // 55Q29 wk2 = ((QMP6988_S64_t)ik->b11 * (QMP6988_S64_t)tx) >> 4; // 28Q34+16-1=43 (39Q30) wk2 = (wk2 * (QMP6988_S64_t)dp) >> 1; // 39Q30+24-1=62 (61Q29) wk3 += wk2; // 55,61->62Q29 wk2 = ((QMP6988_S64_t)ik->bp2 * (QMP6988_S64_t)dp) >> 13; // 29Q43+24-1=52 (39Q30) wk2 = (wk2 * (QMP6988_S64_t)dp) >> 1; // 39Q30+24-1=62 (61Q29) wk3 += wk2; // 62,61->63Q29 wk1 += wk3 >> 14; // Q29 >> 14 -> Q15 wk2 = ((QMP6988_S64_t)ik->b12 * (QMP6988_S64_t)tx); // 29Q53+16-1=45 (45Q53) wk2 = (wk2 * (QMP6988_S64_t)tx) >> 22; // 45Q53+16-1=61 (39Q31) wk2 = (wk2 * (QMP6988_S64_t)dp) >> 1; // 39Q31+24-1=62 (61Q30) wk3 = wk2; // 61Q30 wk2 = ((QMP6988_S64_t)ik->b21 * (QMP6988_S64_t)tx) >> 6; // 29Q60+16-1=45 (39Q54) wk2 = (wk2 * (QMP6988_S64_t)dp) >> 23; // 39Q54+24-1=62 (39Q31) wk2 = (wk2 * (QMP6988_S64_t)dp) >> 1; // 39Q31+24-1=62 (61Q20) wk3 += wk2; // 61,61->62Q30 wk2 = ((QMP6988_S64_t)ik->bp3 * (QMP6988_S64_t)dp) >> 12; // 28Q65+24-1=51 (39Q53) wk2 = (wk2 * (QMP6988_S64_t)dp) >> 23; // 39Q53+24-1=62 (39Q30) wk2 = (wk2 * (QMP6988_S64_t)dp); // 39Q30+24-1=62 (62Q30) wk3 += wk2; // 62,62->63Q30 wk1 += wk3 >> 15; // Q30 >> 15 = Q15 wk1 /= 32767L; wk1 >>= 11; // Q15 >> 7 = Q4 wk1 += ik->b00; // Q4 + 20Q4 // wk1 >>= 4; // 28Q4 -> 24Q0 ret = (QMP6988_S32_t)wk1; return ret; } #endif static void qmp6988_software_reset(qmp6988_data *qmp6988) { /* uint8_t ret = 0; ret = qmp6988_WriteReg(qmp6988->slave, QMP6988_RESET_REG, 0xe6); if (ret == 0) { QMP6988_LOG("qmp6988_software_reset fail!!!\n"); } qmp6988_delay(20); ret = qmp6988_WriteReg(qmp6988->slave, QMP6988_RESET_REG, 0x00); */ } static void qmp6988_set_powermode(qmp6988_data *qmp6988, int power_mode) { uint8_t data; QMP6988_LOG("qmp_set_powermode %d\n", power_mode); // if(power_mode == qmp6988->power_mode) // return; qmp6988->power_mode = power_mode; qmp6988_ReadData(qmp6988->slave, QMP6988_CTRLMEAS_REG, &data, 1); data = data & 0xfc; if (power_mode == QMP6988_SLEEP_MODE) { data |= 0x00; } else if (power_mode == QMP6988_FORCED_MODE) { data |= 0x01; } else if (power_mode == QMP6988_NORMAL_MODE) { data |= 0x03; } qmp6988_WriteReg(qmp6988->slave, QMP6988_CTRLMEAS_REG, data); QMP6988_LOG("qmp_set_powermode 0xf4=0x%x\n", data); qmp6988_delay(20); } static void qmp6988_set_filter(qmp6988_data *qmp6988, unsigned char filter) { uint8_t data; data = (filter & 0x03); qmp6988_WriteReg(qmp6988->slave, QMP6988_CONFIG_REG, data); qmp6988_delay(20); } static void qmp6988_set_oversampling_p(qmp6988_data *qmp6988, unsigned char oversampling_p) { uint8_t data; qmp6988_ReadData(qmp6988->slave, QMP6988_CTRLMEAS_REG, &data, 1); data &= 0xe3; data |= (oversampling_p << 2); qmp6988_WriteReg(qmp6988->slave, QMP6988_CTRLMEAS_REG, data); qmp6988_delay(20); } static void qmp6988_set_oversampling_t(qmp6988_data *qmp6988, unsigned char oversampling_t) { uint8_t data; qmp6988_ReadData(qmp6988->slave, QMP6988_CTRLMEAS_REG, &data, 1); data &= 0x1f; data |= (oversampling_t << 5); qmp6988_WriteReg(qmp6988->slave, QMP6988_CTRLMEAS_REG, data); qmp6988_delay(20); } float qmp6988_calc_altitude(float pressure, float temp) { float altitude; altitude = (pow((101325 / pressure), 1 / 5.257) - 1) * (temp + 273.15) / 0.0065; // QMP6988_LOG("altitude = %f\n" ,altitude); return altitude; } float qmp6988_calc_pressure(qmp6988_data *qmp6988) { uint8_t err = 0; // uint8_t retry_count = 0; QMP6988_U32_t P_read, T_read; QMP6988_S32_t P_raw, T_raw; uint8_t a_data_u8r[6] = {0}; #if defined(QMP6988_CALC_INT) QMP6988_S32_t T_int, P_int; #else float a0, b00; float a1, a2, bt1, bt2, bp1, b11, bp2, b12, b21, bp3; double Tr; #endif /* a_data_u8r[0] = 0x08; retry_count = 0; while (a_data_u8r[0] & 0x08) { err = qmp6988_ReadData(QMP6988_DEVICE_STAT_REG, a_data_u8r, 1); if (err == 0) { QMP6988_LOG("qmp6988 read status reg error!\n"); return; } QMP6988_LOG("qmp6988 read status 0xf3 = 0x%02x\n", a_data_u8r[0]); qmp6988_delay(10); retry_count++; if (retry_count > 5) return; } */ // press err = qmp6988_ReadData(qmp6988->slave, QMP6988_PRESSURE_MSB_REG, a_data_u8r, 6); if (err == 0) { QMP6988_LOG("qmp6988 read press raw error!\n"); return 0.0f; } P_read = (QMP6988_U32_t)( (((QMP6988_U32_t)(a_data_u8r[0])) << SHIFT_LEFT_16_POSITION) | (((QMP6988_U16_t)(a_data_u8r[1])) << SHIFT_LEFT_8_POSITION) | (a_data_u8r[2])); P_raw = (QMP6988_S32_t)(P_read - SUBTRACTOR); /* // temp err = qmp6988_ReadData(QMP6988_TEMPERATURE_MSB_REG, a_data_u8r, 3); if (err == 0) { QMP6988_LOG("qmp6988 read temp raw error!\n"); } */ T_read = (QMP6988_U32_t)( (((QMP6988_U32_t)(a_data_u8r[3])) << SHIFT_LEFT_16_POSITION) | (((QMP6988_U16_t)(a_data_u8r[4])) << SHIFT_LEFT_8_POSITION) | (a_data_u8r[5])); T_raw = (QMP6988_S32_t)(T_read - SUBTRACTOR); #if defined(QMP6988_CALC_INT) T_int = qmp6988_convTx_02e(&(qmp6988->ik), T_raw); P_int = qmp6988_get_pressure_02e(&(qmp6988->ik), P_raw, T_int); qmp6988->temperature = (float)T_int / 256.0f; qmp6988->pressure = (float)P_int / 16.0f; // QMP6988_LOG("int temp=%f Pressure = %f\n",qmp6988->temperature, qmp6988->pressure); #else a0 = qmp6988->fk.a0; b00 = qmp6988->fk.b00; a1 = qmp6988->fk.a1; a2 = qmp6988->fk.a2; bt1 = qmp6988->fk.bt1; bt2 = qmp6988->fk.bt2; bp1 = qmp6988->fk.bp1; b11 = qmp6988->fk.b11; bp2 = qmp6988->fk.bp2; b12 = qmp6988->fk.b12; b21 = qmp6988->fk.b21; bp3 = qmp6988->fk.bp3; Tr = a0 + (a1 * T_raw) + (a2 * T_raw) *T_raw; // Unit centigrade qmp6988->temperature = Tr / 256.0f; // compensation pressure, Unit Pa qmp6988->pressure = b00 + (bt1 * Tr) + (bp1 * P_raw) + (b11 * Tr) *P_raw + (bt2 * Tr) *Tr + (bp2 * P_raw) *P_raw + (b12 * P_raw) *(Tr *Tr) + (b21 * P_raw) *(P_raw *Tr) + (bp3 * P_raw) *(P_raw *P_raw); QMP6988_LOG("float temp=%f Pressure = %f\n", qmp6988->temperature, qmp6988->pressure); #endif qmp6988->altitude = qmp6988_calc_altitude(qmp6988->pressure, qmp6988->temperature); // QMP6988_LOG("altitude = %f\n",qmp6988->altitude); return qmp6988->pressure; } uint8_t qmp6988_init(qmp6988_data *qmp6988) { int32_t ret = sensor_i2c_open(1, QMP6988_SLAVE_ADDRESS_H, I2C_BUS_BIT_RATES_100K, 0); if (ret) { printf("sensor i2c open failed, ret:%d\n", ret); return 0; } ret = qmp6988_device_check(qmp6988); if (ret == 0) { return 0; } qmp6988_software_reset(qmp6988); qmp6988_get_calibration_data(qmp6988); qmp6988_set_powermode(qmp6988, QMP6988_NORMAL_MODE); qmp6988_set_filter(qmp6988, QMP6988_FILTERCOEFF_OFF); qmp6988_set_oversampling_p(qmp6988, QMP6988_OVERSAMPLING_2X); qmp6988_set_oversampling_t(qmp6988, QMP6988_OVERSAMPLING_1X); return 1; } void qmp6988_deinit(void) { int32_t ret = sensor_i2c_close(1); if (ret) { LOGE("SENSOR", "sensor i2c close failed, ret:%d\n", ret); } return; }
YifuLiu/AliOS-Things
hardware/board/haaseduk1/drivers/sensor/drv_baro_qst_qmp6988.c
C
apache-2.0
17,376
/* * Copyright (C) 2015-2021 Alibaba Group Holding Limited */ #ifndef __QMP6988_H #define __QMP6988_H #include <stdio.h> #include "aos/hal/i2c.h" #include "hal_iomux_haas1000.h" #define QMP6988_SLAVE_ADDRESS_L (0x70) #define QMP6988_SLAVE_ADDRESS_H (0x56) #define QMP6988_U16_t unsigned short #define QMP6988_S16_t short #define QMP6988_U32_t unsigned int #define QMP6988_S32_t int #define QMP6988_U64_t unsigned long long #define QMP6988_S64_t long long #define QMP6988_CHIP_ID 0x5C #define QMP6988_CHIP_ID_REG 0xD1 #define QMP6988_RESET_REG 0xE0 /* Device reset register */ #define QMP6988_DEVICE_STAT_REG 0xF3 /* Device state register */ #define QMP6988_CTRLMEAS_REG 0xF4 /* Measurement Condition Control Register */ /* data */ #define QMP6988_PRESSURE_MSB_REG 0xF7 /* Pressure MSB Register */ #define QMP6988_TEMPERATURE_MSB_REG 0xFA /* Temperature MSB Reg */ /* compensation calculation */ #define QMP6988_CALIBRATION_DATA_START 0xA0 /* QMP6988 compensation coefficients */ #define QMP6988_CALIBRATION_DATA_LENGTH 25 #define SHIFT_RIGHT_4_POSITION 4 #define SHIFT_LEFT_2_POSITION 2 #define SHIFT_LEFT_4_POSITION 4 #define SHIFT_LEFT_5_POSITION 5 #define SHIFT_LEFT_8_POSITION 8 #define SHIFT_LEFT_12_POSITION 12 #define SHIFT_LEFT_16_POSITION 16 /* power mode */ #define QMP6988_SLEEP_MODE 0x00 #define QMP6988_FORCED_MODE 0x01 #define QMP6988_NORMAL_MODE 0x03 #define QMP6988_CTRLMEAS_REG_MODE__POS 0 #define QMP6988_CTRLMEAS_REG_MODE__MSK 0x03 #define QMP6988_CTRLMEAS_REG_MODE__LEN 2 /* oversampling */ #define QMP6988_OVERSAMPLING_SKIPPED 0x00 #define QMP6988_OVERSAMPLING_1X 0x01 #define QMP6988_OVERSAMPLING_2X 0x02 #define QMP6988_OVERSAMPLING_4X 0x03 #define QMP6988_OVERSAMPLING_8X 0x04 #define QMP6988_OVERSAMPLING_16X 0x05 #define QMP6988_OVERSAMPLING_32X 0x06 #define QMP6988_OVERSAMPLING_64X 0x07 #define QMP6988_CTRLMEAS_REG_OSRST__POS 5 #define QMP6988_CTRLMEAS_REG_OSRST__MSK 0xE0 #define QMP6988_CTRLMEAS_REG_OSRST__LEN 3 #define QMP6988_CTRLMEAS_REG_OSRSP__POS 2 #define QMP6988_CTRLMEAS_REG_OSRSP__MSK 0x1C #define QMP6988_CTRLMEAS_REG_OSRSP__LEN 3 /* filter */ #define QMP6988_FILTERCOEFF_OFF 0x00 #define QMP6988_FILTERCOEFF_2 0x01 #define QMP6988_FILTERCOEFF_4 0x02 #define QMP6988_FILTERCOEFF_8 0x03 #define QMP6988_FILTERCOEFF_16 0x04 #define QMP6988_FILTERCOEFF_32 0x05 #define QMP6988_CONFIG_REG 0xF1 /*IIR filter co-efficient setting Register*/ #define QMP6988_CONFIG_REG_FILTER__POS 0 #define QMP6988_CONFIG_REG_FILTER__MSK 0x07 #define QMP6988_CONFIG_REG_FILTER__LEN 3 #define SUBTRACTOR 8388608 #define QMP6988_CALC_INT typedef struct qmp6988_cali_data { QMP6988_S32_t COE_a0; QMP6988_S16_t COE_a1; QMP6988_S16_t COE_a2; QMP6988_S32_t COE_b00; QMP6988_S16_t COE_bt1; QMP6988_S16_t COE_bt2; QMP6988_S16_t COE_bp1; QMP6988_S16_t COE_b11; QMP6988_S16_t COE_bp2; QMP6988_S16_t COE_b12; QMP6988_S16_t COE_b21; QMP6988_S16_t COE_bp3; } qmp6988_cali_data; typedef struct qmp6988_fk_data { float a0, b00; float a1, a2, bt1, bt2, bp1, b11, bp2, b12, b21, bp3; } qmp6988_fk_data; typedef struct qmp6988_ik_data { QMP6988_S32_t a0, b00; QMP6988_S32_t a1, a2; QMP6988_S64_t bt1, bt2, bp1, b11, bp2, b12, b21, bp3; } qmp6988_ik_data; typedef struct qmp6988_data { uint8_t slave; uint8_t chip_id; uint8_t power_mode; float temperature; float pressure; float altitude; qmp6988_cali_data qmp6988_cali; #if defined(QMP6988_CALC_INT) qmp6988_ik_data ik; #else qmp6988_fk_data fk; #endif } qmp6988_data; extern uint8_t qmp6988_init(qmp6988_data *qmp6988); extern float qmp6988_calc_pressure(qmp6988_data *qmp6988); extern void qmp6988_deinit(void); #endif
YifuLiu/AliOS-Things
hardware/board/haaseduk1/drivers/sensor/drv_baro_qst_qmp6988.h
C
apache-2.0
4,350
/* * Copyright (C) 2015-2020 Alibaba Group Holding Limited */ #include "drv_mag_qst_qmc5883l.h" #include "aos/hal/i2c.h" #include "ulog/ulog.h" #define QMC5883L_I2C_PORT 1 static int16_t x_max, x_min, z_min, y_max, y_min, z_max; static uint8_t addr; static uint8_t mode; static uint8_t rate; static uint8_t range; static uint8_t oversampling; int qmc5883l_i2c_master_send(const uint8_t *data, uint16_t size, uint32_t timeout) { return sensor_i2c_master_send(QMC5883L_I2C_PORT, QMC5883L_ADDR, data, size, timeout); } int32_t qmc5883l_i2c_master_recv(uint8_t *data, uint16_t size, uint32_t timeout) { return sensor_i2c_master_recv(QMC5883L_I2C_PORT, QMC5883L_ADDR, data, size, timeout); } static void qmc5883l_write_register(uint8_t addr, uint8_t reg, uint8_t data) { uint8_t write_buffer[2] = {reg, data}; qmc5883l_i2c_master_send(write_buffer, 2, 1000); } uint8_t qmc5883l_read_register(uint8_t addr, uint8_t reg) { uint8_t data; qmc5883l_i2c_master_send(&reg, 1, 1000); aos_msleep(2); qmc5883l_i2c_master_recv(&data, 1, 1000); return data; } uint8_t qmc5883l_read_len(uint8_t addr, uint8_t reg, uint8_t *buf, uint8_t len) { qmc5883l_i2c_master_send(&reg, 1, 1000); aos_msleep(20); qmc5883l_i2c_master_recv(buf, len, 1000); return 1; } static void qmc5883l_reconfig() { qmc5883l_write_register(addr, QMC5883L_CONFIG, oversampling | range | rate | mode); qmc5883l_write_register(addr, QMC5883L_CONFIG2, 0x1); } void qmc5883l_resetCalibration(void); static void qmc5883l_reset() { qmc5883l_write_register(addr, QMC5883L_RESET, 0x01); qmc5883l_reconfig(); qmc5883l_resetCalibration(); } void qmc5883l_setOversampling(int x) { switch (x) { case 512: oversampling = QMC5883L_CONFIG_OS512; break; case 256: oversampling = QMC5883L_CONFIG_OS256; break; case 128: oversampling = QMC5883L_CONFIG_OS128; break; case 64: oversampling = QMC5883L_CONFIG_OS64; break; default: break; } qmc5883l_reconfig(); } static void qmc5883l_setRange(int x) { switch (x) { case 2: range = QMC5883L_CONFIG_2GAUSS; break; case 8: range = QMC5883L_CONFIG_8GAUSS; break; default: break; } qmc5883l_reconfig(); } void qmc5883l_setSamplingRate(int x) { switch (x) { case 10: rate = QMC5883L_CONFIG_10HZ; break; case 50: rate = QMC5883L_CONFIG_50HZ; break; case 100: rate = QMC5883L_CONFIG_100HZ; break; case 200: rate = QMC5883L_CONFIG_200HZ; break; default: break; } qmc5883l_reconfig(); } static void _qmc5883l_init() { /* This assumes the wire library has been initialized. */ addr = QMC5883L_ADDR; oversampling = QMC5883L_CONFIG_OS512; range = QMC5883L_CONFIG_8GAUSS; rate = QMC5883L_CONFIG_200HZ; mode = QMC5883L_CONFIG_CONT; qmc5883l_reset(); } int qmc5883l_ready() { return qmc5883l_read_register(addr, QMC5883L_STATUS) & QMC5883L_STATUS_DRDY; } int qmc5883l_readRaw(int16_t *x, int16_t *y, int16_t *z) { uint8_t data[6]; uint32_t timeout = 10000; while (!qmc5883l_ready() && (timeout--)) ; if (!qmc5883l_read_len(addr, QMC5883L_X_LSB, data, 6)) return 0; *x = data[0] | (data[1] << 8); *y = data[2] | (data[3] << 8); *z = data[4] | (data[5] << 8); return 1; } void qmc5883l_resetCalibration(void) { x_max = y_max = z_max = INT16_MIN; x_min = y_min = z_min = INT16_MAX; } int qmc5883l_readHeading() { int16_t x_org, y_org, z_org; float x_offset, y_offset, z_offset; float x_fit, y_fit, z_fit; if (!qmc5883l_readRaw(&x_org, &y_org, &z_org)) return 0; /* Update the observed boundaries of the measurements */ x_min = x_org < x_min ? x_org : x_min; x_max = x_org > x_max ? x_org : x_max; y_min = y_org < y_min ? y_org : y_min; y_max = y_org > y_max ? y_org : y_max; z_min = z_org < z_min ? z_org : z_min; z_max = z_org > z_max ? z_org : z_max; /* Bail out if not enough data is available. */ if (x_min == x_max || y_min == y_max || z_max == z_min) return 0; /* Recenter the measurement by subtracting the average */ x_offset = (x_max + x_min) / 2.0; y_offset = (y_max + y_min) / 2.0; z_offset = (z_max + z_min) / 2.0; x_fit = (x_org - x_offset) * 1000.0 / (x_max - x_min); y_fit = (y_org - y_offset) * 1000.0 / (y_max - y_min); z_fit = (z_org - z_offset) * 1000.0 / (z_max - z_min); LOGD("SENSOR", "fix[%f,%f,%f],\n", x_fit, y_fit, z_fit); int heading = 180.0 * atan2(x_fit, y_fit) / M_PI; heading = (heading <= 0) ? (heading + 360) : heading; return heading; } void qmc5883l_init(void) { int32_t ret = sensor_i2c_open(QMC5883L_I2C_PORT, QMC5883L_ADDR, I2C_BUS_BIT_RATES_100K, 0); if (ret) { LOGE("SENSOR", "sensor i2c open failed, ret:%d\n", ret); return; } _qmc5883l_init(); } void qmc5883l_deinit(void) { int32_t ret = sensor_i2c_close(QMC5883L_I2C_PORT); if (ret) { LOGE("SENSOR", "sensor i2c close failed, ret:%d\n", ret); } return; }
YifuLiu/AliOS-Things
hardware/board/haaseduk1/drivers/sensor/drv_mag_qst_qmc5883l.c
C
apache-2.0
5,462
/* * Copyright (C) 2015-2020 Alibaba Group Holding Limited */ #ifndef QMC5883L_H #define QMC5883L_H /* The default I2C address of this chip */ #define QMC5883L_ADDR 0x0D /* Register numbers */ #define QMC5883L_X_LSB 0 #define QMC5883L_X_MSB 1 #define QMC5883L_Y_LSB 2 #define QMC5883L_Y_MSB 3 #define QMC5883L_Z_LSB 4 #define QMC5883L_Z_MSB 5 #define QMC5883L_STATUS 6 #define QMC5883L_TEMP_LSB 7 #define QMC5883L_TEMP_MSB 8 #define QMC5883L_CONFIG 9 #define QMC5883L_CONFIG2 10 #define QMC5883L_RESET 11 #define QMC5883L_RESERVED 12 #define QMC5883L_CHIP_ID 13 /* Bit values for the STATUS register */ #define QMC5883L_STATUS_DRDY 1 #define QMC5883L_STATUS_OVL 2 #define QMC5883L_STATUS_DOR 4 /* Oversampling values for the CONFIG register */ #define QMC5883L_CONFIG_OS512 0b00000000 #define QMC5883L_CONFIG_OS256 0b01000000 #define QMC5883L_CONFIG_OS128 0b10000000 #define QMC5883L_CONFIG_OS64 0b11000000 /* Range values for the CONFIG register */ #define QMC5883L_CONFIG_2GAUSS 0b00000000 #define QMC5883L_CONFIG_8GAUSS 0b00010000 /* Rate values for the CONFIG register */ #define QMC5883L_CONFIG_10HZ 0b00000000 #define QMC5883L_CONFIG_50HZ 0b00000100 #define QMC5883L_CONFIG_100HZ 0b00001000 #define QMC5883L_CONFIG_200HZ 0b00001100 /* Mode values for the CONFIG register */ #define QMC5883L_CONFIG_STANDBY 0b00000000 #define QMC5883L_CONFIG_CONT 0b00000001 /* Apparently M_PI isn't available in all environments. */ #ifndef M_PI #define M_PI 3.14159265358979323846264338327950288 #endif extern int qmc5883l_readHeading(); extern void qmc5883l_init(void); extern void qmc5883l_deinit(void); #endif /*_QMC5883L_H_*/
YifuLiu/AliOS-Things
hardware/board/haaseduk1/drivers/sensor/drv_mag_qst_qmc5883l.h
C
apache-2.0
1,668
/* * Copyright (C) 2015-2021 Alibaba Group Holding Limited */ #include "drv_mag_qst_qmc6310.h" #include "aos/kernel.h" #include "ulog/ulog.h" #include <math.h> #include <stdlib.h> #define QMC6310_I2C_PORT 1 uint8_t chipid = 0; uint8_t mag_addr; static int16_t x_max, x_min, z_min, y_max, y_min, z_max; static uint8_t addr; static uint8_t mode; static uint8_t rate; static uint8_t range; static uint8_t oversampling; static unsigned char sensor_mask[4] = { 0x80, 0xA0, 0xB0, 0xC0 }; static QMC6310_map c_map; int qmc6310_i2c_master_send(const uint8_t *data, uint16_t size, uint32_t timeout) { return sensor_i2c_master_send(1, mag_addr, data, size, timeout); } int32_t qmc6310_i2c_master_recv(uint8_t *data, uint16_t size, uint32_t timeout) { return sensor_i2c_master_recv(1, mag_addr, data, size, timeout); } uint8_t qmc6310_read_register(uint8_t addr, uint8_t reg) { uint8_t data; qmc6310_i2c_master_send(&reg, 1, 1000); aos_msleep(2); qmc6310_i2c_master_recv(&data, 1, 1000); return data; } int qmc6310_read_block(uint8_t addr, uint8_t *data, uint8_t len) { #if defined(QST_USE_SW_I2C) return qst_sw_readreg(mag_addr, addr, data, len); #else sensor_i2c_mem_read(1, mag_addr, addr, 1, data, len, 100); return 1; #endif } int qmc6310_write_reg(uint8_t addr, uint8_t data) { #if defined(QST_USE_SW_I2C) return qst_sw_writereg(mag_addr, addr, data); #else uint8_t write_buffer[2] = {addr, data}; return qmc6310_i2c_master_send(write_buffer, 2, 1000); #endif } static void qmc6310_set_layout(int layout) { if (layout == 0) { c_map.sign[AXIS_X] = 1; c_map.sign[AXIS_Y] = 1; c_map.sign[AXIS_Z] = 1; c_map.map[AXIS_X] = AXIS_X; c_map.map[AXIS_Y] = AXIS_Y; c_map.map[AXIS_Z] = AXIS_Z; } else if (layout == 1) { c_map.sign[AXIS_X] = -1; c_map.sign[AXIS_Y] = 1; c_map.sign[AXIS_Z] = 1; c_map.map[AXIS_X] = AXIS_Y; c_map.map[AXIS_Y] = AXIS_X; c_map.map[AXIS_Z] = AXIS_Z; } else if (layout == 2) { c_map.sign[AXIS_X] = -1; c_map.sign[AXIS_Y] = -1; c_map.sign[AXIS_Z] = 1; c_map.map[AXIS_X] = AXIS_X; c_map.map[AXIS_Y] = AXIS_Y; c_map.map[AXIS_Z] = AXIS_Z; } else if (layout == 3) { c_map.sign[AXIS_X] = 1; c_map.sign[AXIS_Y] = -1; c_map.sign[AXIS_Z] = 1; c_map.map[AXIS_X] = AXIS_Y; c_map.map[AXIS_Y] = AXIS_X; c_map.map[AXIS_Z] = AXIS_Z; } else if (layout == 4) { c_map.sign[AXIS_X] = -1; c_map.sign[AXIS_Y] = 1; c_map.sign[AXIS_Z] = -1; c_map.map[AXIS_X] = AXIS_X; c_map.map[AXIS_Y] = AXIS_Y; c_map.map[AXIS_Z] = AXIS_Z; } else if (layout == 5) { c_map.sign[AXIS_X] = 1; c_map.sign[AXIS_Y] = 1; c_map.sign[AXIS_Z] = -1; c_map.map[AXIS_X] = AXIS_Y; c_map.map[AXIS_Y] = AXIS_X; c_map.map[AXIS_Z] = AXIS_Z; } else if (layout == 6) { c_map.sign[AXIS_X] = 1; c_map.sign[AXIS_Y] = -1; c_map.sign[AXIS_Z] = -1; c_map.map[AXIS_X] = AXIS_X; c_map.map[AXIS_Y] = AXIS_Y; c_map.map[AXIS_Z] = AXIS_Z; } else if (layout == 7) { c_map.sign[AXIS_X] = -1; c_map.sign[AXIS_Y] = -1; c_map.sign[AXIS_Z] = -1; c_map.map[AXIS_X] = AXIS_Y; c_map.map[AXIS_Y] = AXIS_X; c_map.map[AXIS_Z] = AXIS_Z; } else { c_map.sign[AXIS_X] = 1; c_map.sign[AXIS_Y] = 1; c_map.sign[AXIS_Z] = 1; c_map.map[AXIS_X] = AXIS_X; c_map.map[AXIS_Y] = AXIS_Y; c_map.map[AXIS_Z] = AXIS_Z; } } static int qmc6310_get_chipid(void) { int ret = 0; ret = qmc6310_read_block(QMC6310_CHIP_ID_REG, &chipid, 1); if (ret == 0) { LOGD("SENSOR", "change_iic_addr = 0x3c\n"); mag_addr = QMC6310N_IIC_ADDR; } else { LOGE("SENSOR", "QMC6310_get_chipid chipid = 0x%x\n", chipid); return 1; } ret = qmc6310_read_block(QMC6310_CHIP_ID_REG, &chipid, 1); if (ret == 0) { LOGD("SENSOR", "change_iic_addr = 0x1c\n"); mag_addr = QMC6310U_IIC_ADDR; } else { LOGD("SENSOR", "QMC6310N_get_chipid chipid = 0x%x,i2c_addr = 0x3c\n", chipid); return 1; } ret = qmc6310_read_block(QMC6310_CHIP_ID_REG, &chipid, 1); if (ret == 0) { LOGD("SENSOR", "Get_Chip_ID_Failed!\n"); return 0; } else { LOGD("SENSOR", "QMC6310U_get_chipid chipid = 0x%x,i2c_addr = 0x1c\n", chipid); return 1; } return 1; } uint8_t qmc6310_read_mag_xyz(float *data) { int res; unsigned char mag_data[6]; short hw_d[3] = {0}; short raw_c[3]; int t1 = 0; unsigned char rdy = 0; /* Check status register for data availability */ while (!(rdy & 0x01) && (t1 < 5)) { rdy = QMC6310_STATUS_REG; res = qmc6310_read_block(QMC6310_STATUS_REG, &rdy, 1); if (res == 0) return 0; t1++; } mag_data[0] = QMC6310_DATA_OUT_X_LSB_REG; res = qmc6310_read_block(QMC6310_DATA_OUT_X_LSB_REG, mag_data, 6); if (res == 0) { return 0; } hw_d[0] = (short)(((mag_data[1]) << 8) | mag_data[0]); hw_d[1] = (short)(((mag_data[3]) << 8) | mag_data[2]); hw_d[2] = (short)(((mag_data[5]) << 8) | mag_data[4]); #if 1 // Unit:mG 1G = 100uT = 1000mG // printf("Hx=%d, Hy=%d, Hz=%d\n",hw_d[0],hw_d[1],hw_d[2]); raw_c[AXIS_X] = (int)(c_map.sign[AXIS_X] * hw_d[c_map.map[AXIS_X]]); raw_c[AXIS_Y] = (int)(c_map.sign[AXIS_Y] * hw_d[c_map.map[AXIS_Y]]); raw_c[AXIS_Z] = (int)(c_map.sign[AXIS_Z] * hw_d[c_map.map[AXIS_Z]]); data[0] = (float)raw_c[0] / 10.0f; data[1] = (float)raw_c[1] / 10.0f; data[2] = (float)raw_c[2] / 10.0f; #endif return res; } void qmc6310_resetCalibration() { x_max = y_max = z_max = INT16_MIN; x_min = y_min = z_min = INT16_MAX; } int qmc6310_readHeading() { int16_t x_org, y_org, z_org; float x_offset, y_offset, z_offset; float x_fit, y_fit, z_fit; int res; unsigned char mag_data[6]; short hw_d[3] = {0}; short raw_c[3]; float data[3]; int t1 = 0; unsigned char rdy = 0; /* Check status register for data availability */ while (!(rdy & 0x01) && (t1 < 5)) { rdy = QMC6310_STATUS_REG; res = qmc6310_read_block(QMC6310_STATUS_REG, &rdy, 1); if (res == 0) return 0; t1++; } mag_data[0] = QMC6310_DATA_OUT_X_LSB_REG; res = qmc6310_read_block(QMC6310_DATA_OUT_X_LSB_REG, mag_data, 6); if (res == 0) { return 0; } x_org = (short)(((mag_data[1]) << 8) | mag_data[0]); y_org = (short)(((mag_data[3]) << 8) | mag_data[2]); z_org = (short)(((mag_data[5]) << 8) | mag_data[4]); LOGD("SENSOR", "org[%d,%d,%d],\n", x_org, y_org, z_org); x_min = x_org < x_min ? x_org : x_min; x_max = x_org > x_max ? x_org : x_max; y_min = y_org < y_min ? y_org : y_min; y_max = y_org > y_max ? y_org : y_max; z_min = z_org < z_min ? z_org : z_min; z_max = z_org > z_max ? z_org : z_max; /* Bail out if not enough data is available. */ if (x_min == x_max || y_min == y_max || z_max == z_min) return 0; /* Recenter the measurement by subtracting the average */ x_offset = (x_max + x_min) / 2.0; y_offset = (y_max + y_min) / 2.0; z_offset = (z_max + z_min) / 2.0; x_fit = (x_org - x_offset) * 1000.0 / (x_max - x_min); y_fit = (y_org - y_offset) * 1000.0 / (y_max - y_min); z_fit = (z_org - z_offset) * 1000.0 / (z_max - z_min); // printf("fix[%f,%f,%f],\n", x_fit, y_fit, z_fit); LOGD("SENSOR", "fix[%f,%f,%f],\n", x_fit, y_fit, z_fit); int heading = 180.0 * atan2(x_fit, y_fit) / M_PI; heading = (heading <= 0) ? (heading + 360) : heading; return heading; } /* Set the sensor mode */ int qmc6310_set_mode(unsigned char mode) { int err = 0; unsigned char ctrl1_value = 0; err = qmc6310_read_block(QMC6310_CTL_REG_ONE, &ctrl1_value, 1); ctrl1_value = (ctrl1_value & (~0x03)) | mode; LOGD("SENSOR", "QMC6310_set_mode, 0x0A = [%02x]->[%02x] \r\n", QMC6310_CTL_REG_ONE, ctrl1_value); err = qmc6310_write_reg(QMC6310_CTL_REG_ONE, ctrl1_value); return err; } int qmc6310_set_output_data_rate(unsigned char rate) { int err = 0; unsigned char ctrl1_value = 0; err = qmc6310_read_block(QMC6310_CTL_REG_ONE, &ctrl1_value, 1); ctrl1_value = (ctrl1_value & (~0xE8)) | (rate << 5); LOGD("SENSOR", "QMC6310_set_output_data_rate, 0x0A = [%02x]->[%02x] \r\n", QMC6310_CTL_REG_ONE, ctrl1_value); err = qmc6310_write_reg(QMC6310_CTL_REG_ONE, ctrl1_value); return err; } static int qmc6308_enable(void) { int ret = 0; if (chipid == 0x80) { qmc6310_write_reg(0x0a, 0xc3); qmc6310_write_reg(0x0b, 0x00); qmc6310_write_reg(0x0d, 0x40); } else { qmc6310_write_reg(0x0a, 0x63); qmc6310_write_reg(0x0b, 0x08); qmc6310_write_reg(0x0d, 0x40); } return ret; } static int qmc6310_enable(void) { int ret = 0; qmc6310_write_reg(0x0d, 0x40); qmc6310_write_reg(0x29, 0x06); qmc6310_write_reg(0x0a, 0x0F); // 0XA9=ODR =100HZ 0XA5 = 50HZ qmc6310_write_reg(0x0b, 0x00); // 30 GS return 1; } int qmc6310_init(void) { mag_addr = QMC6310U_IIC_ADDR; int32_t ret = sensor_i2c_open(1, mag_addr, I2C_BUS_BIT_RATES_100K, 0); if (ret) { LOGE("SENSOR", "sensor i2c open failed, ret:%d\n", ret); return 0; } ret = qmc6310_get_chipid(); if (ret == 0) { return 0; } qmc6310_set_layout(0); qmc6310_enable(); { unsigned char ctrl_value; qmc6310_read_block(QMC6310_CTL_REG_ONE, &ctrl_value, 1); LOGD("SENSOR", "QMC6310 0x%x=0x%x \r\n", QMC6310_CTL_REG_ONE, ctrl_value); qmc6310_read_block(QMC6310_CTL_REG_TWO, &ctrl_value, 1); LOGD("SENSOR", "QMC6310 0x%x=0x%x \r\n", QMC6310_CTL_REG_TWO, ctrl_value); qmc6310_read_block(0x0d, &ctrl_value, 1); LOGD("SENSOR", "QMC6310 0x%x=0x%x \r\n", 0x0d, ctrl_value); } return 1; } void qmc6310_deinit(void) { int32_t ret = sensor_i2c_close(QMC6310_I2C_PORT); if (ret) { LOGE("SENSOR", "sensor i2c close failed, ret:%d\n", ret); } return; }
YifuLiu/AliOS-Things
hardware/board/haaseduk1/drivers/sensor/drv_mag_qst_qmc6310.c
C
apache-2.0
10,396
/* * Copyright (C) 2015-2021 Alibaba Group Holding Limited */ #ifndef __QMC6310_H #define __QMC6310_H #include "k_api.h" #include <math.h> #include <stdbool.h> #include "aos/hal/i2c.h" #include "hal_iomux_haas1000.h" /* vendor chip id*/ #define QMC6308_IIC_ADDR 0x2c #define QMC6310U_IIC_ADDR 0x1c #define QMC6310N_IIC_ADDR 0x3c #define QMC6310_CHIP_ID_REG 0x00 /*data output register*/ #define QMC6310_DATA_OUT_X_LSB_REG 0x01 #define QMC6310_DATA_OUT_X_MSB_REG 0x02 #define QMC6310_DATA_OUT_Y_LSB_REG 0x03 #define QMC6310_DATA_OUT_Y_MSB_REG 0x04 #define QMC6310_DATA_OUT_Z_LSB_REG 0x05 #define QMC6310_DATA_OUT_Z_MSB_REG 0x06 /*Status registers */ #define QMC6310_STATUS_REG 0x09 /* configuration registers */ #define QMC6310_CTL_REG_ONE 0x0A /* Contrl register one */ #define QMC6310_CTL_REG_TWO 0x0B /* Contrl register two */ /* Magnetic Sensor Operating Mode MODE[1:0]*/ #define QMC6310_SUSPEND_MODE 0x00 #define QMC6310_NORMAL_MODE 0x01 #define QMC6310_SINGLE_MODE 0x02 #define QMC6310_H_PFM_MODE 0x03 /*data output rate OSR2[2:0]*/ #define OUTPUT_DATA_RATE_800HZ 0x00 #define OUTPUT_DATA_RATE_400HZ 0x01 #define OUTPUT_DATA_RATE_200HZ 0x02 #define OUTPUT_DATA_RATE_100HZ 0x03 /*oversample Ratio OSR[1]*/ #define OVERSAMPLE_RATE_256 0x01 #define OVERSAMPLE_RATE_128 0x00 #define SET_RESET_ON 0x00 #define SET_ONLY_ON 0x01 #define SET_RESET_OFF 0x02 #define QMC6310_DEFAULT_DELAY 200 enum { AXIS_X = 0, AXIS_Y = 1, AXIS_Z = 2, AXIS_TOTAL }; typedef struct { signed char sign[3]; unsigned char map[3]; } QMC6310_map; extern int qmc6310_init(void); extern uint8_t qmc6310_read_mag_xyz(float *data); extern int qmc6310_write_reg(uint8_t addr, uint8_t data); extern int qmc6310_read_block(uint8_t addr, uint8_t *data, uint8_t len); extern int qmc6310_readHeading(); extern void qmc6310_deinit(void); #endif
YifuLiu/AliOS-Things
hardware/board/haaseduk1/drivers/sensor/drv_mag_qst_qmc6310.h
C
apache-2.0
2,146
/* * Copyright (C) 2015-2021 Alibaba Group Holding Limited */ /**********************************CHT8305编程说明***************************************/ // CHT8305兼容I2C/SMBus通讯协议,操作简单,读取温湿度数据分三步操作: // 1)主机向从机地址(有4种可选)发送读0x00寄存器指令,此操作将启动温湿度转换; // [指令结构:start+address(ack)+Reg(ack/unack)+stop] // 2)等待转换完成(15ms); // 3)主机读取从机数据————00:16bit温度数据;01:16bit湿度数据。两个寄存器数据可以一次性读取。 // [指令结构:start+address(ack)+T高8位(ack)+T低8位(ack)+H高8位(ack)+H低8位(ack)+stop] // 特别提醒:1)VCC上电时序要先于或等于I2C上电时序 // 2)从波形上看,每个bit的SDA上升沿和下降沿应充分包裹SCL的上升沿和下降沿 // 3) 建议CHT8305独享一个I2C总线,否则需要保证总线上每个star都对应一个stop; // 4) 采用外部电阻上拉时,MCU的IO口应配置成开漏模式; /****************************************************************************************/ #include "drv_temp_humi_sensylink_cht8305.h" #include "aos/kernel.h" #include "ulog/ulog.h" #include <math.h> #include <stdlib.h> #define CHT8305_I2C_PORT 1 #define CHT8305_ADDRESS 0x40 void cht8305_init(void) { int32_t ret = sensor_i2c_open(CHT8305_I2C_PORT, CHT8305_ADDRESS, I2C_BUS_BIT_RATES_400K, 0); if (ret) { printf("sensor i2c open failed, ret:%d\n", ret); return; } } // get temp and humidity void cht8305_getTempHumidity(float *humidity, float *temperature) { char reg = 0; uint8_t buf[4] = {0}; unsigned int cht8305_temp = 0; unsigned int cht8305_humi = 0; sensor_i2c_master_send(CHT8305_I2C_PORT, CHT8305_ADDRESS, &reg, 1, 1000); aos_msleep(30); sensor_i2c_master_recv(CHT8305_I2C_PORT, CHT8305_ADDRESS, buf, 4, 1000); // printf("%d-%d-%d-%d\n",buf[0],buf[1],buf[2],buf[3]); cht8305_temp = (buf[0] << 8) + buf[1]; if (cht8305_temp & 0xFFFC) { // *temperature = (175.72f * (float)value) / 65536.0f - 46.85f; *temperature = (165.0f * (float)cht8305_temp) / 65536.0f - 40.0f; LOGD("SENDOR", "temperature: %2f\n", *temperature); } else { LOGE("SENDOR", "Error on temp\n"); return 1; } cht8305_humi = (buf[2] << 8) + buf[3]; if (cht8305_humi & 0xFFFE) { // *humidity = (((float)cht8305_humi) / 65535.0f); *humidity = ((125.0f * (float)cht8305_humi) / 65535.0f) - 6.0f; LOGD("SENDOR", "humidity: %f\n", *humidity); } else { LOGE("SENDOR", "Error on humidity\n"); return 1; } } void cht8305_deinit(void) { int32_t ret = sensor_i2c_close(CHT8305_I2C_PORT); if (ret) { LOGE("SENSOR", "sensor i2c close failed, ret:%d\n", ret); } return; }
YifuLiu/AliOS-Things
hardware/board/haaseduk1/drivers/sensor/drv_temp_humi_sensylink_cht8305.c
C
apache-2.0
2,912
/* * Copyright (C) 2015-2021 Alibaba Group Holding Limited */ #ifndef _CH8305_H_ #define _CH8305_H_ #include "aos/hal/i2c.h" #include <math.h> #include <stdbool.h> extern void cht8305_init(); extern void cht8305_getTempHumidity(float *humidity, float *temperature); extern void cht8305_deinit(void); #endif
YifuLiu/AliOS-Things
hardware/board/haaseduk1/drivers/sensor/drv_temp_humi_sensylink_cht8305.h
C
apache-2.0
312
/* * Copyright (C) 2015-2020 Alibaba Group Holding Limited */ #include "drv_temp_humi_si_si7006.h" #include "aos/kernel.h" #include "ulog/ulog.h" #include <math.h> #include <stdlib.h> /*========================================================================*/ /* PUBLIC FUNCTIONS */ /*========================================================================*/ #define SI7006_I2C_PORT 1 int32_t si7006_i2c_master_send(const uint8_t *data, uint16_t size, uint32_t timeout) { return sensor_i2c_master_send(SI7006_I2C_PORT, SI7006_ADDRESS, data, size, timeout); } int32_t si7006_i2c_master_recv(uint8_t *data, uint16_t size, uint32_t timeout) { return sensor_i2c_master_recv(SI7006_I2C_PORT, SI7006_ADDRESS, data, size, timeout); } void si7006_init(void) { int32_t ret = sensor_i2c_open(SI7006_I2C_PORT, SI7006_ADDRESS, I2C_BUS_BIT_RATES_400K, 0); if (ret) { printf("sensor i2c open failed, ret:%d\n", ret); return; } } uint8_t si7006_getVer(void) { uint8_t reg[2] = {SI7006_READ_Firmware_Revision_0, SI7006_READ_Firmware_Revision_1 }; uint8_t version = 0; si7006_i2c_master_send(reg, 2, 1000); aos_msleep(30); si7006_i2c_master_recv(&version, 1, 1000); // LOGI("SENSOR","ver:0x%2x\n",version); return version; } void si7006_getID(uint8_t *id_buf) { uint8_t reg[4] = {SI7006_READ_ID_LOW_0, SI7006_READ_ID_LOW_1, SI7006_READ_ID_HIGH_0, SI7006_READ_ID_HIGH_1 }; si7006_i2c_master_send(reg, 2, 1000); aos_msleep(30); si7006_i2c_master_recv(id_buf, 4, 1000); si7006_i2c_master_send(&reg[2], 2, 1000); aos_msleep(30); si7006_i2c_master_recv(&id_buf[4], 4, 1000); return; } bool si7006_getTemperature(float *temperature) { uint8_t reg = SI7006_MEAS_TEMP_NO_MASTER_MODE; uint8_t read_data[2] = {0}; unsigned int value; si7006_i2c_master_send(&reg, 1, 1000); aos_msleep(30); si7006_i2c_master_recv(read_data, 2, 1000); value = (read_data[0] << 8) | read_data[1]; LOGI("SENSOR", "%0x -- %0x -->0x%x\n", read_data[0], read_data[1], value); // A temperature measurement will always return XXXXXX00 in the LSB field. if (value & 0xFFFC) { *temperature = (175.72f * (float)value) / 65536.0f - 46.85f; LOGI("SENDOR", "temperature: %2f\n", *temperature); } else { LOGE("SENDOR", "Error on temp\n"); return 1; } return 0; } /* i2c – the i2c device dev_addr – device address mem_addr – mem address mem_addr_size – mem address data – i2c master send data size – i2c master send data size */ bool si7006_getHumidity(float *humidity) { uint8_t reg = SI7006_MEAS_REL_HUMIDITY_NO_MASTER_MODE; uint8_t read_data[3] = {0}; unsigned int value; si7006_i2c_master_send(&reg, 1, 1000); aos_msleep(30); si7006_i2c_master_recv(read_data, 2, 1000); value = (read_data[0] << 8) | read_data[1]; LOGI("SENSOR", "%0x -- %0x -->0x%x\n", read_data[0], read_data[1], value); if (value & 0xFFFE) { *humidity = ((125.0f * (float)value) / 65535.0f) - 6.0f; LOGI("SENDOR", "humidity: %f\n", *humidity); } else { LOGE("SENDOR", "Error on humidity\n"); return 1; } return 0; } // get temp and humidity void si7006_getTempHumidity(float *humidity, float *temperature) { si7006_getTemperature(temperature); si7006_getHumidity(humidity); } void si7006_deinit(void) { int32_t ret = sensor_i2c_close(SI7006_I2C_PORT); if (ret) { LOGE("SENSOR", "sensor i2c close failed, ret:%d\n", ret); } return; }
YifuLiu/AliOS-Things
hardware/board/haaseduk1/drivers/sensor/drv_temp_humi_si_si7006.c
C
apache-2.0
3,755
/* * Copyright (C) 2015-2020 Alibaba Group Holding Limited */ #include "aos/hal/i2c.h" #include <math.h> #include <stdbool.h> #ifndef SI7006_h #define SI7006_h #define SI7006_ADDRESS 0x40 #define SI7006_TAG 0x06 #define SI7006_MEAS_REL_HUMIDITY_MASTER_MODE 0xE5 #define SI7006_MEAS_REL_HUMIDITY_NO_MASTER_MODE 0xF5 #define SI7006_MEAS_TEMP_MASTER_MODE 0xE3 #define SI7006_MEAS_TEMP_NO_MASTER_MODE 0xF3 #define SI7006_READ_OLD_TEMP 0xE0 #define SI7006_RESET 0xFE #define SI7006_READ_ID_LOW_0 0xFA #define SI7006_READ_ID_LOW_1 0x0F #define SI7006_READ_ID_HIGH_0 0xFC #define SI7006_READ_ID_HIGH_1 0xC9 #define SI7006_READ_Firmware_Revision_0 0x84 #define SI7006_READ_Firmware_Revision_1 0xB8 extern void si7006_init(void); extern uint8_t si7006_getVer(void); extern void si7006_getID(uint8_t *id_buf); extern bool si7006_getTemperature(float *temperature); extern bool si7006_getHumidity(float *humidity); extern void si7006_getTempHumidity(float *humidity, float *temperature); extern void si7006_deinit(void); #endif
YifuLiu/AliOS-Things
hardware/board/haaseduk1/drivers/sensor/drv_temp_humi_si_si7006.h
C
apache-2.0
1,187
#include <stdint.h> #include <stddef.h> #include <aos/errno.h> #include <vfsdev/i2c_dev.h> #include "ulog/ulog.h" #define EDU_MAX_I2C_PORT 4 static int g_i2c_fd[EDU_MAX_I2C_PORT] = {-1, -1, -1, -1}; int32_t sensor_i2c_open(uint32_t port, uint16_t dev_addr, uint32_t freq, uint32_t address_width) { int ret = 0; int *p_fd = NULL; char name[16] = {0}; io_i2c_control_u c; if (port >= EDU_MAX_I2C_PORT) return -EINVAL; p_fd = &g_i2c_fd[port]; if (*p_fd >= 0) { LOGE("SENSOR", "i2c%d is already opened\r\n", port); return -EALREADY; } memset(&c, 0, sizeof(io_i2c_control_u)); snprintf(name, sizeof(name), "/dev/i2c%d", port); *p_fd = open(name, 0); if (*p_fd < 0) { LOGE("SENSOR", "open %s failed, fd:%d\r\n", name, *p_fd); return -EIO; } c.c.addr = dev_addr; /* sensor's address */ c.c.addr_width = address_width; /* 7-bit address */ c.c.role = 1; /* master mode */ ret = ioctl(*p_fd, IOC_I2C_SET_CONFIG, (unsigned long)&c); c.freq = freq; ret += ioctl(*p_fd, IOC_I2C_SET_FREQ, (unsigned long)&c); if (ret) { LOGE("SENSOR", "IOC_I2C_SET_CONFIG or IOC_I2C_SET_FREQ on %s failed, ret:%d\r\n", name, ret); close(*p_fd); *p_fd = -1; } return ret; } int32_t sensor_i2c_master_send(uint32_t port, uint16_t dev_addr, const uint8_t *data, uint16_t size, uint32_t timeout) { int *p_fd = NULL; int ret = -1; io_i2c_data_t d; p_fd = &g_i2c_fd[port]; if ((port >= EDU_MAX_I2C_PORT) || (*p_fd < 0)) return -EINVAL; memset(&d, 0, sizeof(io_i2c_data_t)); d.addr = dev_addr; d.data = data; d.length = size; d.maddr = 0; d.mlength = 0; d.timeout = timeout; ret = ioctl(*p_fd, IOC_I2C_MASTER_TX, (unsigned long)&d); return ret; } int32_t sensor_i2c_master_recv(uint32_t port, uint16_t dev_addr, uint8_t *data, uint16_t size, uint32_t timeout) { int *p_fd = NULL; int ret = -1; io_i2c_data_t d; p_fd = &g_i2c_fd[port]; if ((port >= EDU_MAX_I2C_PORT) || (*p_fd < 0)) return -EINVAL; memset(&d, 0, sizeof(io_i2c_data_t)); d.addr = dev_addr; d.data = data; d.length = size; d.maddr = 0; d.mlength = 0; d.timeout = timeout; ret = ioctl(*p_fd, IOC_I2C_MASTER_RX, (unsigned long)&d); return ret; } int32_t sensor_i2c_mem_write(uint32_t port, uint16_t dev_addr, uint16_t mem_addr, uint16_t mem_addr_size, const uint8_t *data, uint16_t size, uint32_t timeout) { int *p_fd = NULL; int ret = -1; io_i2c_data_t d; p_fd = &g_i2c_fd[port]; if ((port >= EDU_MAX_I2C_PORT) || (*p_fd < 0)) return -EIO; memset(&d, 0, sizeof(io_i2c_data_t)); d.addr = dev_addr; d.data = data; d.length = size; d.maddr = mem_addr; d.mlength = mem_addr_size; d.timeout = timeout; ret = ioctl(*p_fd, IOC_I2C_MEM_TX, (unsigned long)&d); return ret; } int32_t sensor_i2c_mem_read(uint32_t port, uint16_t dev_addr, uint16_t mem_addr, uint16_t mem_addr_size, uint8_t *data, uint16_t size, uint32_t timeout) { int *p_fd = NULL; int ret = -1; io_i2c_data_t d; p_fd = &g_i2c_fd[port]; if ((port >= EDU_MAX_I2C_PORT) || (*p_fd < 0)) return -EIO; memset(&d, 0, sizeof(io_i2c_data_t)); d.addr = dev_addr; d.data = data; d.length = size; d.maddr = mem_addr; d.mlength = mem_addr_size; d.timeout = timeout; ret = ioctl(*p_fd, IOC_I2C_MEM_RX, (unsigned long)&d); return ret; } int32_t sensor_i2c_close(uint32_t port) { int *p_fd = NULL; p_fd = &g_i2c_fd[port]; if ((port >= EDU_MAX_I2C_PORT) || (*p_fd < 0)) { LOGE("SENSOR", "invalid port:%d or fd:%d\r\n", port, *p_fd); return -EIO; } close(*p_fd); *p_fd = -1; return 0; }
YifuLiu/AliOS-Things
hardware/board/haaseduk1/drivers/sensor/sensor_i2c_api.c
C
apache-2.0
4,044
#include "aos/hal/gpio.h" #include "hal_iomux_haas1000.h" static gpio_dev_t wdg_gpio = {0, 0, NULL}; static int watchdog_flag = 0; void watchdog_feeddog(void) { if (watchdog_flag == 1) { return; } if (wdg_gpio.port == 0) { wdg_gpio.port = HAL_IOMUX_PIN_P4_5; wdg_gpio.config = OUTPUT_PUSH_PULL; hal_gpio_init(&wdg_gpio); } hal_gpio_output_toggle(&wdg_gpio); } void watchdog_stopfeed(void) { watchdog_flag = 1; } void watchdog_feeddog_user(void) { if (wdg_gpio.port == 0) { wdg_gpio.port = HAL_IOMUX_PIN_P4_5; wdg_gpio.config = OUTPUT_PUSH_PULL; hal_gpio_init(&wdg_gpio); } hal_gpio_output_toggle(&wdg_gpio); }
YifuLiu/AliOS-Things
hardware/board/haaseduk1/drivers/watchdog.c
C
apache-2.0
722
/* * Copyright (C) 2015-2020 Alibaba Group Holding Limited */ #ifndef WATCHDOG_H #define WATCHDOG_H void watchdog_feeddog(void); void watchdog_stopfeed(void); void watchdog_feeddog_user(void); #endif
YifuLiu/AliOS-Things
hardware/board/haaseduk1/drivers/watchdog.h
C
apache-2.0
205
#include "aos/init.h" #include "board.h" #include "k_config.h" #include "stdio.h" #include <k_api.h> #include <stdio.h> #include <stdlib.h> // #include "aos/yloop.h" #ifdef AOS_COMP_YUNIT #include "yts.h" #endif #include "ota_port.h" // #include "apps.h" #include "hal_trace.h" #include "led.h" /* * If enable this macro for local test, we don't use wifi service to trigger * connection, remember to mask -DALIOS_WIFI_SERVICE and set -DLWIP_SUPPORT=1 in * SDK. */ #if LWIP_SUPPORT #define ALIOS_BES_APP #endif #define BES_SDK 0 #define BES_WIFI_ONLY 1 #define BES_WIFI_BT 2 #define BES_WIFI_BT_MINI 3 /* * main task stask size(byte) */ #define OS_MAIN_TASK_STACK (32 * 1024) #define OS_MAIN_TASK_PRI 32 /* For user config kinit.argc = 0; kinit.argv = NULL; kinit.cli_enable = 0; */ static kinit_t kinit = {0, NULL, 1}; static ktask_t *g_main_task; static ktask_t *g_speech_task = NULL; static ktask_t *g_dsp_task = NULL; uint8_t mesh_open_enalbe = 1; uint32_t g_wifi_factory_test = 0; extern void soc_peripheral_init(); extern void aos_init_done_hook(void); extern void ble_nosignal_uart_bridge_loop(void); extern uint8_t ble_nosignal_start_flag; extern int32_t tg_bt_hal_vendor_hci_set_epta(int32_t state); extern uint8_t epta_hci_set_flag; extern void a7_heartbeat_reboot_enable(int enable); extern uint32_t __aos_lastword_start[]; #ifndef AOS_BINS extern int application_start(int argc, char **argv); #endif #ifdef ENABLE_LATTICE #include "ali_led.h" #include "ali_sensor.h" void ali_lattice_cli_init(); #endif #ifdef CONFIG_ALI_DISPLAY void disp_init(void); #endif static void haas_board_init(void) { #if CONFIG_A7_DSP_ENABLE int init = BES_WIFI_BT; #else int init = BES_WIFI_BT_MINI; #endif int release_version = 1; int ret = 0; #if 1 // def CONFIG_GENIE_DEBUG disable watchdog release_version = 0; #endif platform_init_step0(release_version); printf("%s platform_init_step0 done\n", __func__); #if CONFIG_A7_DSP_ENABLE /*disable it, since output stereo as default*/ // analog_aud_codec_set_dev(1); // haas use spk-L #endif platform_init_step1(init); printf("%s platform_init_step1 done\n", __func__); ASSERT(DEBUG_LASTWORD_RAM_ADDR == (uint32_t)__aos_lastword_start, "DEBUG_LASTWORD_RAM_ADDR(0x%x) is not equel to " "__aos_lastword_start(0x%x)", DEBUG_LASTWORD_RAM_ADDR, (uint32_t)__aos_lastword_start) led_switch(1, LED_ON); led_switch(2, LED_ON); led_switch(3, LED_ON); #if CONFIG_A7_DSP_ENABLE #ifndef CONFIG_GENIE_DEBUG a7_heartbeat_reboot_enable(1); #endif #endif } static void a7_dsp_init(void) { if (!app_enter_factory_wifi_test()) { printf("now a7_dsp_boot\n"); a7_dsp_boot(); } else { printf("app_enter_factory_wifi_test, no a7_dsp_boot\n"); } } static void factory_rf_test(void) { kinit_t kinit = {0, NULL, 1}; printf("wait factory test now...\n"); board_stduart_init(); aos_components_init(&kinit); #ifdef AOS_VENDOR_CLI vendor_cli_register_init(); #endif while (1) { aos_msleep(1000); } } static void aos_main_task_entry(void) { #ifdef AOS_COMP_YUNIT char *parm[4] = {"yts", "kv", "ramfs", "vfs"}; #endif /* user code start */ soc_peripheral_init(); if (app_enter_factory_wifi_test()) { printf("***************************************************************" "*****\n"); printf("Begin wifi factory test ...\n"); printf("***************************************************************" "*****\n"); g_wifi_factory_test = 1; } // ch395_device_dereset(); #ifdef AOS_COMP_CPLUSPLUS cpp_init(); #endif #ifdef AOS_COMP_OSAL_POSIX posix_init(); #endif #ifdef AOS_COMP_YUNIT yts_run(sizeof(parm) / sizeof(parm[0]), &parm[0]); #endif #ifdef ENABLE_LATTICE ali_lattice_cli_init(); #endif #ifdef CONFIG_ALI_DISPLAY disp_init(); #endif aos_init_done_hook(); #if (RHINO_CONFIG_HW_COUNT > 0) soc_hw_timer_init(); #endif #ifndef AOS_BINS if (app_enter_factory_wifi_test() == false) { aos_maintask(); } else { factory_rf_test(); } #endif } int main(void) { int times = 0; /*irq initialized is approved here.But irq triggering is forbidden, which will enter CPU scheduling. Put them in sys_init which will be called after aos_start. Irq for task schedule should be enabled here, such as PendSV for cortex-M4. */ haas_board_init(); // including aos_heap_set(); flash_partition_init(); /*kernel init, malloc can use after this!*/ // krhino_init(); /*main task to run */ krhino_task_dyn_create(&g_main_task, "main_task", 0, OS_MAIN_TASK_PRI, 0, OS_MAIN_TASK_STACK, (task_entry_t)aos_main_task_entry, 1); /*kernel start schedule!*/ // krhino_start(); while (1) { krhino_task_sleep(100); if (times == 10) { led_switch(1, LED_OFF); led_switch(2, LED_OFF); led_switch(3, LED_OFF); times ++; } else { if (times < 11) { times++; } } #ifdef AOS_VENDOR_CLI /*only work when enter ble nosignal*/ if (ble_nosignal_start_flag) { ble_nosignal_uart_bridge_loop(); } #endif if (epta_hci_set_flag) { printf("%d epta_hci_set_flag\n", epta_hci_set_flag); tg_bt_hal_vendor_hci_set_epta(epta_hci_set_flag); epta_hci_set_flag = 0; } } /*never run here*/ return 0; }
YifuLiu/AliOS-Things
hardware/board/haaseduk1/startup/startup.c
C
apache-2.0
5,725
/* File: startup_ARMCM3.S * Purpose: startup file for Cortex-M3 devices. Should use with * GCC for ARM Embedded Processors * Version: V2.0 * Date: 16 August 2013 * /* Copyright (c) 2011 - 2013 ARM LIMITED All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - Neither the name of ARM nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ---------------------------------------------------------------------------*/ .syntax unified .arch armv7-m .section .stack .align 3 #ifdef __STACK_SIZE .equ Stack_Size, __STACK_SIZE #else .equ Stack_Size, 0xc00 #endif .globl __StackTop .globl __StackLimit __StackLimit: .space Stack_Size .size __StackLimit, . - __StackLimit __StackTop: .size __StackTop, . - __StackTop .section .heap .align 3 #ifdef __HEAP_SIZE .equ Heap_Size, __HEAP_SIZE #else .equ Heap_Size, 0x1B000 #endif .globl __HeapBase .globl __HeapLimit __HeapBase: .if Heap_Size .space Heap_Size .endif .size __HeapBase, . - __HeapBase __HeapLimit: .size __HeapLimit, . - __HeapLimit .section .isr_vector .align 2 .globl __isr_vector __isr_vector: .word __StackTop /* Top of Stack */ .word Reset_Handler /* Reset Handler */ .word NMI_Handler /* NMI Handler */ .word HardFault_Handler /* Hard Fault Handler */ .word MemManage_Handler /* MPU Fault Handler */ .word BusFault_Handler /* Bus Fault Handler */ .word UsageFault_Handler /* Usage Fault Handler */ .word 0 /* Reserved */ .word 0 /* Reserved */ .word 0 /* Reserved */ .word 0 /* Reserved */ .word SVC_Handler /* SVCall Handler */ .word DebugMon_Handler /* Debug Monitor Handler */ .word 0 /* Reserved */ .word PendSV_Handler /* PendSV Handler */ .word OS_CPU_SysTickHandler /* SysTick Handler */ /* External interrupts */ .word SDIO_RX_IRQHandler .word SDIO_TX_IRQHandler .word SDIO_RX_CMD_IRQHandler .word SDIO_TX_CMD_IRQHandler .word tls_wl_mac_isr .word Default_Handler .word tls_wl_rx_isr .word tls_wl_mgmt_tx_isr .word tls_wl_data_tx_isr .word PMU_TIMER1_IRQHandler .word PMU_TIMER0_IRQHandler .word PMU_GPIO_WAKE_IRQHandler .word PMU_SDIO_WAKE_IRQHandler .word DMA_Channel0_IRQHandler .word DMA_Channel1_IRQHandler .word DMA_Channel2_IRQHandler .word DMA_Channel3_IRQHandler .word DMA_Channel4_7_IRQHandler .word DMA_BRUST_IRQHandler .word I2C_IRQHandler .word ADC_IRQHandler .word SPI_LS_IRQHandler .word SPI_HS_IRQHandler .word UART0_IRQHandler .word UART1_IRQHandler .word GPIOA_IRQHandler .word TIM0_IRQHandler .word TIM1_IRQHandler .word TIM2_IRQHandler .word TIM3_IRQHandler .word TIM4_IRQHandler .word TIM5_IRQHandler .word WDG_IRQHandler .word PMU_IRQHandler .word FLASH_IRQHandler .word PWM_IRQHandler .word I2S_IRQHandler .word PMU_RTC_IRQHandler .word RSA_IRQHandler .word CRYPTION_IRQHandler .word GPIOB_IRQHandler .word UART2_IRQHandler .size __isr_vector, . - __isr_vector .text .thumb .thumb_func .align 2 .globl Reset_Handler .type Reset_Handler, %function Reset_Handler: /* Firstly it copies data from read only memory to RAM. * * The ranges of copy from/to are specified by following symbols * __etext: LMA of start of the section to copy from. Usually end of text * __data_start__: VMA of start of the section to copy to * __data_end__: VMA of end of the section to copy to * * All addresses must be aligned to 4 bytes boundary. */ ldr r1, =__etext ldr r2, =__data_start__ ldr r3, =__data_end__ .L_loop1: cmp r2, r3 ittt lt ldrlt r0, [r1], #4 strlt r0, [r2], #4 blt .L_loop1 /* Single BSS section scheme. * * The BSS section is specified by following symbols * __bss_start__: start of the BSS section. * __bss_end__: end of the BSS section. * * Both addresses must be aligned to 4 bytes boundary. */ ldr r1, =__bss_start__ ldr r2, =__bss_end__ movs r0, 0 .L_loop2: cmp r1, r2 itt lt strlt r0, [r1], #4 blt .L_loop2 #ifndef __NO_SYSTEM_INIT bl SystemInit #endif bl main .pool .size Reset_Handler, . - Reset_Handler .align 1 .thumb_func .weak Default_Handler .type Default_Handler, %function Default_Handler: b . .size Default_Handler, . - Default_Handler /* Macro to define default handlers. Default handler * will be weak symbol and just dead loops. They can be * overwritten by other handlers */ .macro def_irq_handler handler_name .weak \handler_name .set \handler_name, Default_Handler .endm def_irq_handler NMI_Handler def_irq_handler HardFault_Handler def_irq_handler MemManage_Handler def_irq_handler BusFault_Handler def_irq_handler UsageFault_Handler def_irq_handler SVC_Handler def_irq_handler DebugMon_Handler def_irq_handler PendSV_Handler def_irq_handler OS_CPU_SysTickHandler def_irq_handler SDIO_RX_IRQHandler def_irq_handler SDIO_TX_IRQHandler def_irq_handler SDIO_RX_CMD_IRQHandler def_irq_handler SDIO_TX_CMD_IRQHandler def_irq_handler tls_wl_mac_isr def_irq_handler tls_wl_rx_isr def_irq_handler tls_wl_mgmt_tx_isr def_irq_handler tls_wl_data_tx_isr def_irq_handler PMU_TIMER1_IRQHandler def_irq_handler PMU_TIMER0_IRQHandler def_irq_handler PMU_GPIO_WAKE_IRQHandler def_irq_handler PMU_SDIO_WAKE_IRQHandler def_irq_handler DMA_Channel0_IRQHandler def_irq_handler DMA_Channel1_IRQHandler def_irq_handler DMA_Channel2_IRQHandler def_irq_handler DMA_Channel3_IRQHandler def_irq_handler DMA_Channel4_7_IRQHandler def_irq_handler DMA_BRUST_IRQHandler def_irq_handler I2C_IRQHandler def_irq_handler ADC_IRQHandler def_irq_handler SPI_LS_IRQHandler def_irq_handler SPI_HS_IRQHandler def_irq_handler UART0_IRQHandler def_irq_handler UART1_IRQHandler def_irq_handler GPIOA_IRQHandler def_irq_handler TIM0_IRQHandler def_irq_handler TIM1_IRQHandler def_irq_handler TIM2_IRQHandler def_irq_handler TIM3_IRQHandler def_irq_handler TIM4_IRQHandler def_irq_handler TIM5_IRQHandler def_irq_handler WDG_IRQHandler def_irq_handler PMU_IRQHandler def_irq_handler FLASH_IRQHandler def_irq_handler PWM_IRQHandler def_irq_handler I2S_IRQHandler def_irq_handler PMU_RTC_IRQHandler def_irq_handler RSA_IRQHandler def_irq_handler CRYPTION_IRQHandler def_irq_handler GPIOB_IRQHandler def_irq_handler UART2_IRQHandler .end
YifuLiu/AliOS-Things
hardware/board/haaseduk1/startup/startup_gcc.s
Unix Assembly
apache-2.0
7,931
/* * Copyright (C) 2015-2021 Alibaba Group Holding Limited */ #include "board.h" extern void aos_heap_set(); extern void krhino_tick_proc(void); extern void ioreuse_initial(void); extern int clock_timer_init(void); extern int clock_timer_start(void); extern UART_HandleTypeDef huart1; void board_pre_init(void) { } /** * @general board init entry board_basic_init * @retval None */ void board_basic_init(void) { /*mm heap set*/ aos_heap_set(); } /** * @general board tick init entry board_tick_init * @retval None */ void board_tick_init(void) { } /** * @init the default uart init example. */ void board_stduart_init(void) { // huart1.Instance = USART1; // huart1.Init.BaudRate = 115200; // huart1.Init.WordLength = UART_WORDLENGTH_8B; // huart1.Init.StopBits = UART_STOPBITS_1; // huart1.Init.Parity = UART_PARITY_NONE; // huart1.Init.Mode = UART_MODE_TX_RX; // huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE; // huart1.Init.OverSampling = UART_OVERSAMPLING_16; // huart1.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE; // huart1.Init.ClockPrescaler = UART_PRESCALER_DIV1; // huart1.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT; // if (HAL_UART_Init(&huart1) != HAL_OK) // { // Error_Handler(); // } // if (HAL_UARTEx_SetTxFifoThreshold(&huart1, UART_TXFIFO_THRESHOLD_1_8) != HAL_OK) // { // Error_Handler(); // } // if (HAL_UARTEx_SetRxFifoThreshold(&huart1, UART_RXFIFO_THRESHOLD_1_8) != HAL_OK) // { // Error_Handler(); // } // if (HAL_UARTEx_DisableFifoMode(&huart1) != HAL_OK) // { // Error_Handler(); // } } /** * Enable DMA controller clock */ void board_dma_init(void) { } /** * @brief GPIO Initialization Function * @param None * @retval None */ void board_gpio_init(void) { } /** * @brief WIFI Initialization Function * @param None * @retval None */ void board_wifi_init(void) { } void board_network_init(void) { } void board_kinit_init(kinit_t* init_args) { return; } void board_flash_init(void) { } /** * @brief This function handles System tick timer. */ void systick_handler(void) { krhino_intrpt_enter(); krhino_tick_proc(); krhino_intrpt_exit(); }
YifuLiu/AliOS-Things
hardware/board/stm32u5_b_u585i_iot02a/config/board.c
C
apache-2.0
2,278
/* * Copyright (C) 2015-2021 Alibaba Group Holding Limited */ #ifndef BOARD_H #define BOARD_H #include <stdint.h> #include <stdio.h> #include <stdlib.h> #include "aos/init.h" #include "k_config.h" #include "board.h" #include "aos/hal/uart.h" #include "stm32u5xx_hal.h" void systick_handler(void); void board_flash_init(void); void board_kinit_init(kinit_t* init_args); void board_network_init(void); void board_wifi_init(void); void board_gpio_init(void); void board_dma_init(void); void board_stduart_init(void); void board_tick_init(void); void board_basic_init(void); void board_pre_init(void); #endif
YifuLiu/AliOS-Things
hardware/board/stm32u5_b_u585i_iot02a/config/board.h
C
apache-2.0
609
/** ****************************************************************************** * @file k_config.c * @author MCU China FAE team * @version 1.0 * @date 05/01/2019 * @brief aos porting layer ****************************************************************************** * * COPYRIGHT(c) 2019 STMicroelectronics * ****************************************************************************** */ #include <k_api.h> #include <assert.h> #include <stdio.h> #include <sys/time.h> #if (RHINO_CONFIG_HW_COUNT > 0) void soc_hw_timer_init(void) { } hr_timer_t soc_hr_hw_cnt_get(void) { return 0; //return *(volatile uint64_t *)0xc0000120; } lr_timer_t soc_lr_hw_cnt_get(void) { return 0; } #endif /* RHINO_CONFIG_HW_COUNT */ #if (RHINO_CONFIG_MM_TLF > 0) #if defined (__CC_ARM) /* Keil / armcc */ extern unsigned int Image$$RW_IRAM1$$ZI$$Limit; extern size_t g_iram1_start; extern size_t g_iram1_total_size; k_mm_region_t g_mm_region[1]; int g_region_num = 1; void aos_heap_set() { g_mm_region[0].start = (uint8_t*)&Image$$RW_IRAM1$$ZI$$Limit; g_mm_region[0].len = (g_iram1_start + g_iram1_total_size - (size_t)&Image$$RW_IRAM1$$ZI$$Limit); } #elif defined (__ICCARM__)/* IAR */ int g_region_num = 1; k_mm_region_t g_mm_region[1]; void aos_heap_set() { #pragma section="HEAP" uint8_t* heap_start= (uint8_t*)__section_begin("HEAP"); uint8_t* heap_end=(uint8_t*)__section_end("HEAP"); /* heap_start and heap_len is set by linkscript(*.ld) */ g_mm_region[0].start = heap_start; g_mm_region[0].len = heap_end - heap_start; } #else /* GCC */ extern void *_estack; extern void *__bss_end__; /* __bss_end__ and _estack is set by linkscript(*.ld) heap and stack begins from __bss_end__ to _estack */ k_mm_region_t g_mm_region[1]; int g_region_num = 1; void aos_heap_set() { g_mm_region[0].start = (uint8_t*)&__bss_end__; g_mm_region[0].len = ((uint8_t*)&_estack - (uint8_t*)&__bss_end__) - RHINO_CONFIG_SYSTEM_STACK_SIZE; } #endif #endif #if (RHINO_CONFIG_TASK_STACK_CUR_CHECK > 0) size_t soc_get_cur_sp() { size_t sp = 0; #if defined (__GNUC__)&&!defined(__CC_ARM) asm volatile( "mov %0,sp\n" :"=r"(sp)); #endif return sp; } static void soc_print_stack() { void *cur, *end; int i=0; int *p; end = krhino_cur_task_get()->task_stack_base + krhino_cur_task_get()->stack_size; cur = (void *)soc_get_cur_sp(); p = (int*)cur; while(p < (int*)end) { if(i%4==0) { printf("\r\n%08x:",(uint32_t)p); } printf("%08x ", *p); i++; p++; } printf("\r\n"); return; } #endif void soc_err_proc(kstat_t err) { (void)err; printf("soc_err_proc %d \r\n", err); //krhino_backtrace_now(); #if (RHINO_CONFIG_TASK_STACK_CUR_CHECK > 0) //soc_print_stack(); #endif while(1); } krhino_err_proc_t g_err_proc = soc_err_proc;
YifuLiu/AliOS-Things
hardware/board/stm32u5_b_u585i_iot02a/config/k_config.c
C
apache-2.0
3,006
/** ****************************************************************************** * @file k_config.h * @author MCU China FAE team * @version 1.0 * @date 05/01/2019 * @brief aos porting layer ****************************************************************************** * * COPYRIGHT(c) 2019 STMicroelectronics * ****************************************************************************** */ #ifndef K_CONFIG_H #define K_CONFIG_H /* heap conf */ #ifndef RHINO_CONFIG_MM_BLK #define RHINO_CONFIG_MM_BLK 1 #endif #ifndef RHINO_CONFIG_MM_DEBUG #define RHINO_CONFIG_MM_DEBUG 1 #endif #ifndef RHINO_CONFIG_MM_TLF #define RHINO_CONFIG_MM_TLF 1 #endif #ifndef RHINO_CONFIG_MM_TLF_BLK_SIZE #define RHINO_CONFIG_MM_TLF_BLK_SIZE 1024 #endif /* kernel task conf */ #ifndef RHINO_CONFIG_TASK_INFO #define RHINO_CONFIG_TASK_INFO 1 #endif #ifndef RHINO_CONFIG_TASK_STACK_CUR_CHECK #define RHINO_CONFIG_TASK_STACK_CUR_CHECK 1 #endif #ifndef RHINO_CONFIG_TASK_STACK_OVF_CHECK #define RHINO_CONFIG_TASK_STACK_OVF_CHECK 1 #endif #ifndef RHINO_CONFIG_SCHED_RR #define RHINO_CONFIG_SCHED_RR 1 #endif #ifndef RHINO_CONFIG_TIME_SLICE_DEFAULT #define RHINO_CONFIG_TIME_SLICE_DEFAULT 50 #endif #ifndef RHINO_CONFIG_PRI_MAX #define RHINO_CONFIG_PRI_MAX 62 #endif #ifndef RHINO_CONFIG_USER_PRI_MAX #define RHINO_CONFIG_USER_PRI_MAX (RHINO_CONFIG_PRI_MAX - 2) #endif /* kernel workqueue conf */ #ifndef RHINO_CONFIG_WORKQUEUE #define RHINO_CONFIG_WORKQUEUE 1 #endif #ifndef RHINO_CONFIG_WORKQUEUE_STACK_SIZE #define RHINO_CONFIG_WORKQUEUE_STACK_SIZE 128 #endif /* kernel mm_region conf */ #ifndef RHINO_CONFIG_MM_REGION_MUTEX #define RHINO_CONFIG_MM_REGION_MUTEX 1 #endif /* kernel timer&tick conf */ #ifndef RHINO_CONFIG_HW_COUNT #define RHINO_CONFIG_HW_COUNT 0 #endif #ifndef RHINO_CONFIG_TICKS_PER_SECOND #define RHINO_CONFIG_TICKS_PER_SECOND 1000 #endif /*must reserve enough stack size for timer cb will consume*/ #ifndef RHINO_CONFIG_TIMER_TASK_STACK_SIZE #define RHINO_CONFIG_TIMER_TASK_STACK_SIZE 128 #endif /* kernel intrpt conf */ #ifndef RHINO_CONFIG_INTRPT_STACK_REMAIN_GET #define RHINO_CONFIG_INTRPT_STACK_REMAIN_GET 0 #endif #ifndef RHINO_CONFIG_INTRPT_STACK_OVF_CHECK #define RHINO_CONFIG_INTRPT_STACK_OVF_CHECK 0 #endif /* kernel dyn alloc conf */ #ifndef RHINO_CONFIG_KOBJ_DYN_ALLOC #define RHINO_CONFIG_KOBJ_DYN_ALLOC 1 #endif #if (RHINO_CONFIG_KOBJ_DYN_ALLOC > 0) #ifndef RHINO_CONFIG_K_DYN_TASK_STACK #define RHINO_CONFIG_K_DYN_TASK_STACK 128 #endif #ifndef RHINO_CONFIG_K_DYN_MEM_TASK_PRI #define RHINO_CONFIG_K_DYN_MEM_TASK_PRI 6 #endif #endif /* kernel idle conf */ #ifndef RHINO_CONFIG_IDLE_TASK_STACK_SIZE #define RHINO_CONFIG_IDLE_TASK_STACK_SIZE 32 #endif /* kernel hook conf */ #ifndef RHINO_CONFIG_USER_HOOK #define RHINO_CONFIG_USER_HOOK 0 #endif #ifndef RHINO_CONFIG_CPU_NUM #define RHINO_CONFIG_CPU_NUM 1 #endif #ifndef RHINO_CONFIG_SYSTEM_STACK_SIZE #define RHINO_CONFIG_SYSTEM_STACK_SIZE 0x180 #endif #ifndef RHINO_CONFIG_BACKTRACE #define RHINO_CONFIG_BACKTRACE 1 #endif #ifndef RHINO_CONFIG_PANIC #define RHINO_CONFIG_PANIC 1 #endif #ifndef RHINO_CLI_CONSOLE_USER_INFO_POS #define RHINO_CLI_CONSOLE_USER_INFO_POS 1 #endif #endif /* K_CONFIG_H */
YifuLiu/AliOS-Things
hardware/board/stm32u5_b_u585i_iot02a/config/k_config.h
C
apache-2.0
3,483
/* * Copyright (C) 2015-2021 Alibaba Group Holding Limited */ #ifndef NET_CONFIG_H #define NET_CONFIG_H #endif
YifuLiu/AliOS-Things
hardware/board/stm32u5_b_u585i_iot02a/config/net_config.h
C
apache-2.0
115
/* * Copyright (C) 2015-2021 Alibaba Group Holding Limited */ #include <aos/mtdpart.h> #include <aos/mtd.h> /* Logic partition on flash devices */ const mtd_partition_t mtd_partitions[] = { { .partition_name = "boot1", .partition_name_std = MTD_PART_NAME_BOOTLOADER, .partition_start_addr = 0x0, .partition_length = 0x10000, //64KB .partition_options = 0, }, { .partition_name = "boot_info", .partition_name_std = MTD_PART_NAME_ENV2, .partition_start_addr = 0x10000, //boot information need protect .partition_length = 0x2000, //8KB .partition_options = 0, }, { .partition_name = "boot2A", .partition_name_std = MTD_PART_NAME_2ND_BOOTLOADER, .partition_start_addr = 0x12000, .partition_length = 0x18000, //64KB .partition_options = 0, }, { .partition_name = "RTOSA", .partition_name_std = MTD_PART_NAME_KERNEL, .partition_start_addr = 0x2A000, .partition_length = 0x578000, //5.5MB .partition_options = 0, }, { .partition_name = "boot2B", .partition_name_std = MTD_PART_NAME_2ND_BOOTLOADER2, .partition_start_addr = 0x5A2000, .partition_length = 0x18000, //64KB .partition_options = 0, }, { .partition_name = "RTOSB", .partition_name_std = MTD_PART_NAME_KERNEL2, .partition_start_addr = 0x5BA000, .partition_length = 0x578000, //5.5MB .partition_options = 0, }, { .partition_name = "littleFS", .partition_name_std = MTD_PART_NAME_LITTLEFS, .partition_start_addr = 0xB32000, .partition_length = 0x4AE000, //4792KB .partition_options = 0, }, { .partition_name = "boot1_sec", .partition_name_std = MTD_PART_NAME_BOOTLOADER_SEC, .partition_start_addr = 0xFE0000, .partition_length = 0x10000, //64KB .partition_options = 0, }, { .partition_name = "boot2_info", .partition_name_std = MTD_PART_NAME_ENV, .partition_start_addr = 0xFF0000, .partition_length = 0x1000, //4KB .partition_options = 0, }, { .partition_name = "KV", .partition_name_std = MTD_PART_NAME_KV, .partition_start_addr = 0xFF1000, .partition_length = 0xD000, //52KB .partition_options = 0, }, { .partition_name = "factory", .partition_name_std = MTD_PART_NAME_FACTORY, .partition_start_addr = 0xFFE000, .partition_length = 0x2000, //8KB .partition_options = 0, } }; /* Declare a constant to indicate the defined partitions amount */ const int mtd_partitions_amount = (sizeof(mtd_partitions) / sizeof(mtd_partition_t)); #include <aos/flashpart_core.h> #include <aos/hal/flash.h> static int flash_partitions_init(void) { static aos_flashpart_t partitions[] = { { .dev = { .id = HAL_PARTITION_BOOTLOADER, }, .flash_id = 0, .block_start = 0x0, .block_count = 0x10, }, { .dev = { .id = HAL_PARTITION_PARAMETER_3, }, .flash_id = 0, .block_start = 0x10, .block_count = 0x2, }, { .dev = { .id = HAL_PARTITION_BOOT1, }, .flash_id = 0, .block_start = 0x12, .block_count = 0x18, }, { .dev = { .id = HAL_PARTITION_APPLICATION, }, .flash_id = 0, .block_start = 0x2A, .block_count = 0x578, }, { .dev = { .id = HAL_PARTITION_BOOT1_REDUND, }, .flash_id = 0, .block_start = 0x5A2, .block_count = 0x18, }, { .dev = { .id = HAL_PARTITION_OTA_TEMP, }, .flash_id = 0, .block_start = 0x5BA, .block_count = 0x578, }, { .dev = { .id = HAL_PARTITION_LITTLEFS, }, .flash_id = 0, .block_start = 0xB32, .block_count = 0x4AE, }, { .dev = { .id = HAL_PARTITION_PARAMETER_4, }, .flash_id = 0, .block_start = 0xFE0, .block_count = 0x10, }, { .dev = { .id = HAL_PARTITION_PARAMETER_1, }, .flash_id = 0, .block_start = 0xFF0, .block_count = 0x1, }, { .dev = { .id = HAL_PARTITION_PARAMETER_2, }, .flash_id = 0, .block_start = 0xFF1, .block_count = 0xD, }, { .dev = { .id = HAL_PARTITION_ENV, }, .flash_id = 0, .block_start = 0xFFE, .block_count = 0x2, }, { .dev = { .id = HAL_PARTITION_ENV_REDUND, }, .flash_id = 0, .block_start = 0xFFE, .block_count = 0x2, }, }; for (size_t i = 0; i < sizeof(partitions) / sizeof(partitions[0]); i++) { int ret; ret = aos_flashpart_register(&partitions[i]); if (ret) { for (size_t j = 0; j < i; j++) (void)aos_flashpart_unregister(j); return ret; } } return 0; } LEVEL1_DRIVER_ENTRY(flash_partitions_init)
YifuLiu/AliOS-Things
hardware/board/stm32u5_b_u585i_iot02a/config/partition_conf.c
C
apache-2.0
5,840
/* USER CODE BEGIN Header */ /** ****************************************************************************** * @file hardware/board/stm32u5_b_u585i_iot02a/drivers/main.h * @author MCD Application Team * @brief This file contains all the functions prototypes for the main.c * file. ****************************************************************************** * @attention * * Copyright (c) 2021 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ /* USER CODE END Header */ /* Define to prevent recursive inclusion -------------------------------------*/ #ifndef __MAIN_H #define __MAIN_H #ifdef __cplusplus extern "C" { #endif /* Includes ------------------------------------------------------------------*/ #include "stm32u5xx_hal.h" /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ /* USER CODE END Includes */ /* Exported types ------------------------------------------------------------*/ /* USER CODE BEGIN ET */ /* USER CODE END ET */ /* Exported constants --------------------------------------------------------*/ /* USER CODE BEGIN EC */ /* USER CODE END EC */ /* Exported macro ------------------------------------------------------------*/ /* USER CODE BEGIN EM */ /* USER CODE END EM */ /* Exported functions prototypes ---------------------------------------------*/ /* USER CODE BEGIN EFP */ /* USER CODE END EFP */ /* Private defines -----------------------------------------------------------*/ #define LED2_Pin GPIO_PIN_6 #define LED2_GPIO_Port GPIOH #define LED1_Pin GPIO_PIN_7 #define LED1_GPIO_Port GPIOH /* USER CODE BEGIN Private defines */ /* USER CODE END Private defines */ #ifdef __cplusplus } #endif #endif /* __MAIN_H */
YifuLiu/AliOS-Things
hardware/board/stm32u5_b_u585i_iot02a/drivers/main.h
C
apache-2.0
2,061
/* USER CODE BEGIN Header */ /** ****************************************************************************** * @file stm32u5xx_hal_conf.h * @author MCD Application Team * @brief HAL configuration file. ****************************************************************************** * @attention * * Copyright (c) 2021 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ /* USER CODE END Header */ /* Define to prevent recursive inclusion -------------------------------------*/ #ifndef STM32U5xx_HAL_CONF_H #define STM32U5xx_HAL_CONF_H #ifdef __cplusplus extern "C" { #endif /* Exported types ------------------------------------------------------------*/ /* Exported constants --------------------------------------------------------*/ /* ########################## Module Selection ############################## */ /** * @brief This is the list of modules to be used in the HAL driver */ #define HAL_MODULE_ENABLED /*#define HAL_ADC_MODULE_ENABLED */ /*#define HAL_MDF_MODULE_ENABLED */ /*#define HAL_COMP_MODULE_ENABLED */ /*#define HAL_CORDIC_MODULE_ENABLED */ /*#define HAL_CRC_MODULE_ENABLED */ /*#define HAL_CRYP_MODULE_ENABLED */ /*#define HAL_DAC_MODULE_ENABLED */ /*#define HAL_DMA2D_MODULE_ENABLED */ /*#define HAL_DSI_MODULE_ENABLED */ /*#define HAL_FDCAN_MODULE_ENABLED */ /*#define HAL_FMAC_MODULE_ENABLED */ /*#define HAL_GFXMMU_MODULE_ENABLED */ /*#define HAL_GPU2D_MODULE_ENABLED */ /*#define HAL_GTZC_MODULE_ENABLED */ /*#define HAL_HASH_MODULE_ENABLED */ /*#define HAL_HRTIM_MODULE_ENABLED */ /*#define HAL_IRDA_MODULE_ENABLED */ /*#define HAL_IWDG_MODULE_ENABLED */ /*#define HAL_I2C_MODULE_ENABLED */ /*#define HAL_I2S_MODULE_ENABLED */ /*#define HAL_LPTIM_MODULE_ENABLED */ /*#define HAL_LTDC_MODULE_ENABLED */ /*#define HAL_NAND_MODULE_ENABLED */ /*#define HAL_NOR_MODULE_ENABLED */ /*#define HAL_OPAMP_MODULE_ENABLED */ /*#define HAL_OSPI_MODULE_ENABLED */ /*#define HAL_OTFDEC_MODULE_ENABLED */ /*#define HAL_PCD_MODULE_ENABLED */ /*#define HAL_PKA_MODULE_ENABLED */ /*#define HAL_QSPI_MODULE_ENABLED */ /*#define HAL_RNG_MODULE_ENABLED */ #define HAL_RTC_MODULE_ENABLED /*#define HAL_SAI_MODULE_ENABLED */ /*#define HAL_CRYP_MODULE_ENABLED */ /*#define HAL_SD_MODULE_ENABLED */ /*#define HAL_MMC_MODULE_ENABLED */ /*#define HAL_SMARTCARD_MODULE_ENABLED */ /*#define HAL_SMBUS_MODULE_ENABLED */ /*#define HAL_SPI_MODULE_ENABLED */ /*#define HAL_SRAM_MODULE_ENABLED */ #define HAL_TIM_MODULE_ENABLED /*#define HAL_TSC_MODULE_ENABLED */ /*#define HAL_RAMCFG_MODULE_ENABLED */ #define HAL_UART_MODULE_ENABLED /*#define HAL_USART_MODULE_ENABLED */ /*#define HAL_WWDG_MODULE_ENABLED */ /*#define HAL_DCMI_MODULE_ENABLED */ /*#define HAL_PSSI_MODULE_ENABLED */ #define HAL_ICACHE_MODULE_ENABLED /*#define HAL_DCACHE_MODULE_ENABLED */ /*#define HAL_PCD_MODULE_ENABLED */ /*#define HAL_HCD_MODULE_ENABLED */ /*#define HAL_XSPI_MODULE_ENABLED */ #define HAL_GPIO_MODULE_ENABLED #define HAL_EXTI_MODULE_ENABLED #define HAL_DMA_MODULE_ENABLED #define HAL_RCC_MODULE_ENABLED #define HAL_FLASH_MODULE_ENABLED #define HAL_PWR_MODULE_ENABLED #define HAL_CORTEX_MODULE_ENABLED /* ########################## Oscillator Values adaptation ####################*/ /** * @brief Adjust the value of External High Speed oscillator (HSE) used in your application. * This value is used by the RCC HAL module to compute the system frequency * (when HSE is used as system clock source, directly or through the PLL). */ #if !defined (HSE_VALUE) #define HSE_VALUE 16000000UL /*!< Value of the External oscillator in Hz */ #endif /* HSE_VALUE */ #if !defined (HSE_STARTUP_TIMEOUT) #define HSE_STARTUP_TIMEOUT 100UL /*!< Time out for HSE start up, in ms */ #endif /* HSE_STARTUP_TIMEOUT */ /** * @brief Internal Multiple Speed oscillator (MSI) default value. * This value is the default MSI range value after Reset. */ #if !defined (MSI_VALUE) #define MSI_VALUE 4000000UL /*!< Value of the Internal oscillator in Hz*/ #endif /* MSI_VALUE */ /** * @brief Internal High Speed oscillator (HSI) value. * This value is used by the RCC HAL module to compute the system frequency * (when HSI is used as system clock source, directly or through the PLL). */ #if !defined (HSI_VALUE) #define HSI_VALUE 16000000UL /*!< Value of the Internal oscillator in Hz*/ #endif /* HSI_VALUE */ /** * @brief Internal High Speed oscillator (HSI48) value for USB FS, SDMMC and RNG. * This internal oscillator is mainly dedicated to provide a high precision clock to * the USB peripheral by means of a special Clock Recovery System (CRS) circuitry. * When the CRS is not used, the HSI48 RC oscillator runs on it default frequency * which is subject to manufacturing process variations. */ #if !defined (HSI48_VALUE) #define HSI48_VALUE 48000000UL /*!< Value of the Internal High Speed oscillator for USB FS/SDMMC/RNG in Hz. The real value my vary depending on manufacturing process variations.*/ #endif /* HSI48_VALUE */ /** * @brief Internal Low Speed oscillator (LSI) value. */ #if !defined (LSI_VALUE) #define LSI_VALUE 32000UL /*!< LSI Typical Value in Hz*/ #endif /* LSI_VALUE */ /*!< Value of the Internal Low Speed oscillator in Hz The real value may vary depending on the variations in voltage and temperature.*/ /** * @brief External Low Speed oscillator (LSE) value. * This value is used by the UART, RTC HAL module to compute the system frequency */ #if !defined (LSE_VALUE) #define LSE_VALUE 32768UL /*!< Value of the External Low Speed oscillator in Hz */ #endif /* LSE_VALUE */ #if !defined (LSE_STARTUP_TIMEOUT) #define LSE_STARTUP_TIMEOUT 5000UL /*!< Time out for LSE start up, in ms */ #endif /* LSE_STARTUP_TIMEOUT */ /** * @brief External clock source for SAI1 peripheral * This value is used by the RCC HAL module to compute the SAI1 & SAI2 clock source * frequency. */ #if !defined (EXTERNAL_SAI1_CLOCK_VALUE) #define EXTERNAL_SAI1_CLOCK_VALUE 48000UL /*!< Value of the SAI1 External clock source in Hz*/ #endif /* EXTERNAL_SAI1_CLOCK_VALUE */ /* Tip: To avoid modifying this file each time you need to use different HSE, === you can define the HSE value in your toolchain compiler preprocessor. */ /* ########################### System Configuration ######################### */ /** * @brief This is the HAL system configuration section */ #define VDD_VALUE 3300UL /*!< Value of VDD in mv */ #define TICK_INT_PRIORITY (15UL) /*!< tick interrupt priority (lowest by default) */ #define USE_RTOS 0U #define PREFETCH_ENABLE 1U /*!< Enable prefetch */ /* ########################## Assert Selection ############################## */ /** * @brief Uncomment the line below to expanse the "assert_param" macro in the * HAL drivers code */ /* #define USE_FULL_ASSERT 1U */ /* ################## Register callback feature configuration ############### */ /** * @brief Set below the peripheral configuration to "1U" to add the support * of HAL callback registration/unregistration feature for the HAL * driver(s). This allows user application to provide specific callback * functions thanks to HAL_PPP_RegisterCallback() rather than overwriting * the default weak callback functions (see each stm32u5xx_hal_ppp.h file * for possible callback identifiers defined in HAL_PPP_CallbackIDTypeDef * for each PPP peripheral). */ #define USE_HAL_ADC_REGISTER_CALLBACKS 0U /* ADC register callback disabled */ #define USE_HAL_COMP_REGISTER_CALLBACKS 0U /* COMP register callback disabled */ #define USE_HAL_CORDIC_REGISTER_CALLBACKS 0U /* CORDIC register callback disabled */ #define USE_HAL_CRYP_REGISTER_CALLBACKS 0U /* CRYP register callback disabled */ #define USE_HAL_DAC_REGISTER_CALLBACKS 0U /* DAC register callback disabled */ #define USE_HAL_DCMI_REGISTER_CALLBACKS 0U /* DCMI register callback disabled */ #define USE_HAL_DMA2D_REGISTER_CALLBACKS 0U /* DMA2D register callback disabled */ #define USE_HAL_DSI_REGISTER_CALLBACKS 0U /* DSI register callback disabled */ #define USE_HAL_ETH_REGISTER_CALLBACKS 0U /* ETH register callback disabled */ #define USE_HAL_FDCAN_REGISTER_CALLBACKS 0U /* FDCAN register callback disabled */ #define USE_HAL_FMAC_REGISTER_CALLBACKS 0U /* FMAC register callback disabled */ #define USE_HAL_HASH_REGISTER_CALLBACKS 0U /* HASH register callback disabled */ #define USE_HAL_HCD_REGISTER_CALLBACKS 0U /* HCD register callback disabled */ #define USE_HAL_GFXMMU_REGISTER_CALLBACKS 0U /* GFXMMU register callback disabled */ #define USE_HAL_GPU2D_REGISTER_CALLBACKS 0U /* GPU2D register callback disabled */ #define USE_HAL_I2C_REGISTER_CALLBACKS 0U /* I2C register callback disabled */ #define USE_HAL_IWDG_REGISTER_CALLBACKS 0U /* IWDG register callback disabled */ #define USE_HAL_IRDA_REGISTER_CALLBACKS 0U /* IRDA register callback disabled */ #define USE_HAL_LPTIM_REGISTER_CALLBACKS 0U /* LPTIM register callback disabled */ #define USE_HAL_LTDC_REGISTER_CALLBACKS 0U /* LTDC register callback disabled */ #define USE_HAL_MDF_REGISTER_CALLBACKS 0U /* MDF register callback disabled */ #define USE_HAL_MMC_REGISTER_CALLBACKS 0U /* MMC register callback disabled */ #define USE_HAL_NAND_REGISTER_CALLBACKS 0U /* NAND register callback disabled */ #define USE_HAL_NOR_REGISTER_CALLBACKS 0U /* NOR register callback disabled */ #define USE_HAL_OPAMP_REGISTER_CALLBACKS 0U /* MDIO register callback disabled */ #define USE_HAL_OTFDEC_REGISTER_CALLBACKS 0U /* OTFDEC register callback disabled */ #define USE_HAL_PCD_REGISTER_CALLBACKS 0U /* PCD register callback disabled */ #define USE_HAL_PKA_REGISTER_CALLBACKS 0U /* PKA register callback disabled */ #define USE_HAL_RAMCFG_REGISTER_CALLBACKS 0U /* RAMCFG register callback disabled */ #define USE_HAL_RNG_REGISTER_CALLBACKS 0U /* RNG register callback disabled */ #define USE_HAL_RTC_REGISTER_CALLBACKS 0U /* RTC register callback disabled */ #define USE_HAL_SAI_REGISTER_CALLBACKS 0U /* SAI register callback disabled */ #define USE_HAL_SD_REGISTER_CALLBACKS 0U /* SD register callback disabled */ #define USE_HAL_SDRAM_REGISTER_CALLBACKS 0U /* SDRAM register callback disabled */ #define USE_HAL_SMARTCARD_REGISTER_CALLBACKS 0U /* SMARTCARD register callback disabled */ #define USE_HAL_SMBUS_REGISTER_CALLBACKS 0U /* SMBUS register callback disabled */ #define USE_HAL_SPI_REGISTER_CALLBACKS 0U /* SPI register callback disabled */ #define USE_HAL_SRAM_REGISTER_CALLBACKS 0U /* SRAM register callback disabled */ #define USE_HAL_TIM_REGISTER_CALLBACKS 1U /* TIM register callback enabled */ #define USE_HAL_TSC_REGISTER_CALLBACKS 0U /* TSC register callback disabled */ #define USE_HAL_UART_REGISTER_CALLBACKS 1U /* UART register callback enabled */ #define USE_HAL_USART_REGISTER_CALLBACKS 0U /* USART register callback disabled */ #define USE_HAL_WWDG_REGISTER_CALLBACKS 0U /* WWDG register callback disabled */ /* ################## SPI peripheral configuration ########################## */ /* CRC FEATURE: Use to activate CRC feature inside HAL SPI Driver * Activated: CRC code is present inside driver * Deactivated: CRC code cleaned from driver */ #define USE_SPI_CRC 0U /* ################## SDMMC peripheral configuration ######################### */ #define USE_SD_TRANSCEIVER 0U /*!< use uSD Transceiver */ /* Includes ------------------------------------------------------------------*/ /** * @brief Include module's header file */ #ifdef HAL_RCC_MODULE_ENABLED #include "stm32u5xx_hal_rcc.h" #endif /* HAL_RCC_MODULE_ENABLED */ #ifdef HAL_GPIO_MODULE_ENABLED #include "stm32u5xx_hal_gpio.h" #endif /* HAL_GPIO_MODULE_ENABLED */ #ifdef HAL_ICACHE_MODULE_ENABLED #include "stm32u5xx_hal_icache.h" #endif /* HAL_ICACHE_MODULE_ENABLED */ #ifdef HAL_DCACHE_MODULE_ENABLED #include "stm32u5xx_hal_dcache.h" #endif /* HAL_DCACHE_MODULE_ENABLED */ #ifdef HAL_GTZC_MODULE_ENABLED #include "stm32u5xx_hal_gtzc.h" #endif /* HAL_GTZC_MODULE_ENABLED */ #ifdef HAL_DMA_MODULE_ENABLED #include "stm32u5xx_hal_dma.h" #endif /* HAL_DMA_MODULE_ENABLED */ #ifdef HAL_DMA2D_MODULE_ENABLED #include "stm32u5xx_hal_dma2d.h" #endif /* HAL_DMA2D_MODULE_ENABLED */ #ifdef HAL_DSI_MODULE_ENABLED #include "stm32u5xx_hal_dsi.h" #endif /* HAL_DSI_MODULE_ENABLED */ #ifdef HAL_CORTEX_MODULE_ENABLED #include "stm32u5xx_hal_cortex.h" #endif /* HAL_CORTEX_MODULE_ENABLED */ #ifdef HAL_PKA_MODULE_ENABLED #include "stm32u5xx_hal_pka.h" #endif /* HAL_PKA_MODULE_ENABLED */ #ifdef HAL_ADC_MODULE_ENABLED #include "stm32u5xx_hal_adc.h" #endif /* HAL_ADC_MODULE_ENABLED */ #ifdef HAL_COMP_MODULE_ENABLED #include "stm32u5xx_hal_comp.h" #endif /* HAL_COMP_MODULE_ENABLED */ #ifdef HAL_CRC_MODULE_ENABLED #include "stm32u5xx_hal_crc.h" #endif /* HAL_CRC_MODULE_ENABLED */ #ifdef HAL_CRYP_MODULE_ENABLED #include "stm32u5xx_hal_cryp.h" #endif /* HAL_CRYP_MODULE_ENABLED */ #ifdef HAL_DAC_MODULE_ENABLED #include "stm32u5xx_hal_dac.h" #endif /* HAL_DAC_MODULE_ENABLED */ #ifdef HAL_FLASH_MODULE_ENABLED #include "stm32u5xx_hal_flash.h" #endif /* HAL_FLASH_MODULE_ENABLED */ #ifdef HAL_HASH_MODULE_ENABLED #include "stm32u5xx_hal_hash.h" #endif /* HAL_HASH_MODULE_ENABLED */ #ifdef HAL_SRAM_MODULE_ENABLED #include "stm32u5xx_hal_sram.h" #endif /* HAL_SRAM_MODULE_ENABLED */ #ifdef HAL_MMC_MODULE_ENABLED #include "stm32u5xx_hal_mmc.h" #endif /* HAL_MMC_MODULE_ENABLED */ #ifdef HAL_NOR_MODULE_ENABLED #include "stm32u5xx_hal_nor.h" #endif /* HAL_NOR_MODULE_ENABLED */ #ifdef HAL_NAND_MODULE_ENABLED #include "stm32u5xx_hal_nand.h" #endif /* HAL_NAND_MODULE_ENABLED */ #ifdef HAL_I2C_MODULE_ENABLED #include "stm32u5xx_hal_i2c.h" #endif /* HAL_I2C_MODULE_ENABLED */ #ifdef HAL_IWDG_MODULE_ENABLED #include "stm32u5xx_hal_iwdg.h" #endif /* HAL_IWDG_MODULE_ENABLED */ #ifdef HAL_LPTIM_MODULE_ENABLED #include "stm32u5xx_hal_lptim.h" #endif /* HAL_LPTIM_MODULE_ENABLED */ #ifdef HAL_LTDC_MODULE_ENABLED #include "stm32u5xx_hal_ltdc.h" #endif /* HAL_LTDC_MODULE_ENABLED */ #ifdef HAL_OPAMP_MODULE_ENABLED #include "stm32u5xx_hal_opamp.h" #endif /* HAL_OPAMP_MODULE_ENABLED */ #ifdef HAL_PWR_MODULE_ENABLED #include "stm32u5xx_hal_pwr.h" #endif /* HAL_PWR_MODULE_ENABLED */ #ifdef HAL_OSPI_MODULE_ENABLED #include "stm32u5xx_hal_ospi.h" #endif /* HAL_OSPI_MODULE_ENABLED */ #ifdef HAL_RNG_MODULE_ENABLED #include "stm32u5xx_hal_rng.h" #endif /* HAL_RNG_MODULE_ENABLED */ #ifdef HAL_RTC_MODULE_ENABLED #include "stm32u5xx_hal_rtc.h" #endif /* HAL_RTC_MODULE_ENABLED */ #ifdef HAL_SAI_MODULE_ENABLED #include "stm32u5xx_hal_sai.h" #endif /* HAL_SAI_MODULE_ENABLED */ #ifdef HAL_SD_MODULE_ENABLED #include "stm32u5xx_hal_sd.h" #endif /* HAL_SD_MODULE_ENABLED */ #ifdef HAL_SMBUS_MODULE_ENABLED #include "stm32u5xx_hal_smbus.h" #endif /* HAL_SMBUS_MODULE_ENABLED */ #ifdef HAL_SPI_MODULE_ENABLED #include "stm32u5xx_hal_spi.h" #endif /* HAL_SPI_MODULE_ENABLED */ #ifdef HAL_TIM_MODULE_ENABLED #include "stm32u5xx_hal_tim.h" #endif /* HAL_TIM_MODULE_ENABLED */ #ifdef HAL_TSC_MODULE_ENABLED #include "stm32u5xx_hal_tsc.h" #endif /* HAL_TSC_MODULE_ENABLED */ #ifdef HAL_UART_MODULE_ENABLED #include "stm32u5xx_hal_uart.h" #endif /* HAL_UART_MODULE_ENABLED */ #ifdef HAL_USART_MODULE_ENABLED #include "stm32u5xx_hal_usart.h" #endif /* HAL_USART_MODULE_ENABLED */ #ifdef HAL_IRDA_MODULE_ENABLED #include "stm32u5xx_hal_irda.h" #endif /* HAL_IRDA_MODULE_ENABLED */ #ifdef HAL_SMARTCARD_MODULE_ENABLED #include "stm32u5xx_hal_smartcard.h" #endif /* HAL_SMARTCARD_MODULE_ENABLED */ #ifdef HAL_WWDG_MODULE_ENABLED #include "stm32u5xx_hal_wwdg.h" #endif /* HAL_WWDG_MODULE_ENABLED */ #ifdef HAL_PCD_MODULE_ENABLED #include "stm32u5xx_hal_pcd.h" #endif /* HAL_PCD_MODULE_ENABLED */ #ifdef HAL_HCD_MODULE_ENABLED #include "stm32u5xx_hal_hcd.h" #endif /* HAL_HCD_MODULE_ENABLED */ #ifdef HAL_CORDIC_MODULE_ENABLED #include "stm32u5xx_hal_cordic.h" #endif /* HAL_CORDIC_MODULE_ENABLED */ #ifdef HAL_DCMI_MODULE_ENABLED #include "stm32u5xx_hal_dcmi.h" #endif /* HAL_DCMI_MODULE_ENABLED */ #ifdef HAL_EXTI_MODULE_ENABLED #include "stm32u5xx_hal_exti.h" #endif /* HAL_EXTI_MODULE_ENABLED */ #ifdef HAL_FDCAN_MODULE_ENABLED #include "stm32u5xx_hal_fdcan.h" #endif /* HAL_FDCAN_MODULE_ENABLED */ #ifdef HAL_FMAC_MODULE_ENABLED #include "stm32u5xx_hal_fmac.h" #endif /* HAL_FMAC_MODULE_ENABLED */ #ifdef HAL_GFXMMU_MODULE_ENABLED #include "stm32u5xx_hal_gfxmmu.h" #endif /* HAL_GFXMMU_MODULE_ENABLED */ #ifdef HAL_GPU2D_MODULE_ENABLED #include "stm32u5xx_hal_gpu2d.h" #endif /* HAL_GPU2D_MODULE_ENABLED */ #ifdef HAL_OTFDEC_MODULE_ENABLED #include "stm32u5xx_hal_otfdec.h" #endif /* HAL_OTFDEC_MODULE_ENABLED */ #ifdef HAL_PSSI_MODULE_ENABLED #include "stm32u5xx_hal_pssi.h" #endif /* HAL_PSSI_MODULE_ENABLED */ #ifdef HAL_RAMCFG_MODULE_ENABLED #include "stm32u5xx_hal_ramcfg.h" #endif /* HAL_RAMCFG_MODULE_ENABLED */ #ifdef HAL_MDF_MODULE_ENABLED #include "stm32u5xx_hal_mdf.h" #endif /* HAL_MDF_MODULE_ENABLED */ #ifdef HAL_XSPI_MODULE_ENABLED #include "stm32u5xx_hal_xspi.h" #endif /* HAL_XSPI_MODULE_ENABLED */ /* Exported macro ------------------------------------------------------------*/ #ifdef USE_FULL_ASSERT /** * @brief The assert_param macro is used for function's parameters check. * @param expr: If expr is false, it calls assert_failed function * which reports the name of the source file and the source * line number of the call that failed. * If expr is true, it returns no value. * @retval None */ #define assert_param(expr) ((expr) ? (void)0U : assert_failed((uint8_t *)__FILE__, __LINE__)) /* Exported functions ------------------------------------------------------- */ void assert_failed(uint8_t *file, uint32_t line); #else #define assert_param(expr) ((void)0U) #endif /* USE_FULL_ASSERT */ #ifdef __cplusplus } #endif #endif /* STM32U5xx_HAL_CONF_H */
YifuLiu/AliOS-Things
hardware/board/stm32u5_b_u585i_iot02a/drivers/stm32u5xx_hal_conf.h
C
apache-2.0
19,142
/* USER CODE BEGIN Header */ /** ****************************************************************************** * @file stm32u5xx_hal_msp.c * @brief This file provides code for the MSP Initialization * and de-Initialization codes. ****************************************************************************** * @attention * * Copyright (c) 2021 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ /* USER CODE END Header */ /* Includes ------------------------------------------------------------------*/ #include "main.h" /* USER CODE BEGIN Includes */ /* USER CODE END Includes */ /* Private typedef -----------------------------------------------------------*/ /* USER CODE BEGIN TD */ /* USER CODE END TD */ /* Private define ------------------------------------------------------------*/ /* USER CODE BEGIN Define */ /* USER CODE END Define */ /* Private macro -------------------------------------------------------------*/ /* USER CODE BEGIN Macro */ /* USER CODE END Macro */ /* Private variables ---------------------------------------------------------*/ /* USER CODE BEGIN PV */ /* USER CODE END PV */ /* Private function prototypes -----------------------------------------------*/ /* USER CODE BEGIN PFP */ /* USER CODE END PFP */ /* External functions --------------------------------------------------------*/ /* USER CODE BEGIN ExternalFunctions */ /* USER CODE END ExternalFunctions */ /* USER CODE BEGIN 0 */ /* USER CODE END 0 */ /** * Initializes the Global MSP. */ void HAL_MspInit(void) { /* USER CODE BEGIN MspInit 0 */ /* USER CODE END MspInit 0 */ __HAL_RCC_PWR_CLK_ENABLE(); /* System interrupt init*/ /* USER CODE BEGIN MspInit 1 */ /* USER CODE END MspInit 1 */ } /** * @brief UART MSP Initialization * This function configures the hardware resources used in this example * @param huart: UART handle pointer * @retval None */ void HAL_UART_MspInit(UART_HandleTypeDef* huart) { GPIO_InitTypeDef GPIO_InitStruct = {0}; RCC_PeriphCLKInitTypeDef PeriphClkInit = {0}; if(huart->Instance==USART1) { /* USER CODE BEGIN USART1_MspInit 0 */ /* USER CODE END USART1_MspInit 0 */ /** Initializes the peripherals clock */ PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USART1; PeriphClkInit.Usart1ClockSelection = RCC_USART1CLKSOURCE_PCLK2; if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK) { Error_Handler(); } /* Peripheral clock enable */ __HAL_RCC_USART1_CLK_ENABLE(); __HAL_RCC_GPIOA_CLK_ENABLE(); /**USART1 GPIO Configuration PA10 ------> USART1_RX PA9 ------> USART1_TX */ GPIO_InitStruct.Pin = GPIO_PIN_10|GPIO_PIN_9; GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; GPIO_InitStruct.Alternate = GPIO_AF7_USART1; HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); /* USER CODE BEGIN USART1_MspInit 1 */ /* USER CODE END USART1_MspInit 1 */ } } /** * @brief UART MSP De-Initialization * This function freeze the hardware resources used in this example * @param huart: UART handle pointer * @retval None */ void HAL_UART_MspDeInit(UART_HandleTypeDef* huart) { if(huart->Instance==USART1) { /* USER CODE BEGIN USART1_MspDeInit 0 */ /* USER CODE END USART1_MspDeInit 0 */ /* Peripheral clock disable */ __HAL_RCC_USART1_CLK_DISABLE(); /**USART1 GPIO Configuration PA10 ------> USART1_RX PA9 ------> USART1_TX */ HAL_GPIO_DeInit(GPIOA, GPIO_PIN_10|GPIO_PIN_9); /* USER CODE BEGIN USART1_MspDeInit 1 */ /* USER CODE END USART1_MspDeInit 1 */ } } /* USER CODE BEGIN 1 */ /* USER CODE END 1 */
YifuLiu/AliOS-Things
hardware/board/stm32u5_b_u585i_iot02a/drivers/stm32u5xx_hal_msp.c
C
apache-2.0
4,030
/* USER CODE BEGIN Header */ /** ****************************************************************************** * @file hardware/board/stm32u5_b_u585i_iot02a/drivers/stm32u5xx_it.c * @author MCD Application Team * @brief Main Interrupt Service Routines. * This file provides template for all exceptions handler and * peripherals interrupt service routine. ****************************************************************************** * @attention * * Copyright (c) 2021 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ /* USER CODE END Header */ /* Includes ------------------------------------------------------------------*/ #include "stm32u5xx_it.h" #include "main.h" #include "board.h" #include "aos/debug.h" /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ /* USER CODE END Includes */ /* Private typedef -----------------------------------------------------------*/ /* USER CODE BEGIN TD */ /* USER CODE END TD */ /* Private define ------------------------------------------------------------*/ /* USER CODE BEGIN PD */ /* USER CODE END PD */ /* Private macro -------------------------------------------------------------*/ /* USER CODE BEGIN PM */ /* USER CODE END PM */ /* Private variables ---------------------------------------------------------*/ /* USER CODE BEGIN PV */ /* USER CODE END PV */ /* Private function prototypes -----------------------------------------------*/ /* USER CODE BEGIN PFP */ /* USER CODE END PFP */ /* Private user code ---------------------------------------------------------*/ /* USER CODE BEGIN 0 */ /* USER CODE END 0 */ /* External variables --------------------------------------------------------*/ extern TIM_HandleTypeDef htim6; /* USER CODE BEGIN EV */ /* USER CODE END EV */ /******************************************************************************/ /* Cortex Processor Interruption and Exception Handlers */ /******************************************************************************/ /** * @brief This function handles Non maskable interrupt. */ void NMI_Handler(void) { /* USER CODE BEGIN NonMaskableInt_IRQn 0 */ /* USER CODE END NonMaskableInt_IRQn 0 */ /* USER CODE BEGIN NonMaskableInt_IRQn 1 */ while (1) { } /* USER CODE END NonMaskableInt_IRQn 1 */ } /** * @brief This function handles Debug monitor. */ void DebugMon_Handler(void) { /* USER CODE BEGIN DebugMonitor_IRQn 0 */ /* USER CODE END DebugMonitor_IRQn 0 */ /* USER CODE BEGIN DebugMonitor_IRQn 1 */ /* USER CODE END DebugMonitor_IRQn 1 */ } /******************************************************************************/ /* STM32U5xx Peripheral Interrupt Handlers */ /* Add here the Interrupt Handlers for the used peripherals. */ /* For the available peripheral interrupt handler names, */ /* please refer to the startup file (startup_stm32u5xx.s). */ /******************************************************************************/ void SysTick_Handler(void) { if (g_sys_stat == RHINO_RUNNING) { systick_handler(); } } /* USER CODE BEGIN 1 */ /* USER CODE END 1 */
YifuLiu/AliOS-Things
hardware/board/stm32u5_b_u585i_iot02a/drivers/stm32u5xx_it.c
C
apache-2.0
3,580
/* USER CODE BEGIN Header */ /** ****************************************************************************** * @file hardware/board/stm32u5_b_u585i_iot02a/drivers/stm32u5xx_it.h * @author MCD Application Team * @brief This file contains the headers of the interrupt handlers. ****************************************************************************** * @attention * * Copyright (c) 2021 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ /* USER CODE END Header */ /* Define to prevent recursive inclusion -------------------------------------*/ #ifndef __STM32U5xx_IT_H #define __STM32U5xx_IT_H #ifdef __cplusplus extern "C" { #endif /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ /* USER CODE END Includes */ /* Exported types ------------------------------------------------------------*/ /* USER CODE BEGIN ET */ /* USER CODE END ET */ /* Exported constants --------------------------------------------------------*/ /* USER CODE BEGIN EC */ /* USER CODE END EC */ /* Exported macro ------------------------------------------------------------*/ /* USER CODE BEGIN EM */ /* USER CODE END EM */ /* Exported functions prototypes ---------------------------------------------*/ void NMI_Handler(void); void HardFault_Handler(void); void MemManage_Handler(void); void BusFault_Handler(void); void UsageFault_Handler(void); void DebugMon_Handler(void); void TIM6_IRQHandler(void); /* USER CODE BEGIN EFP */ /* USER CODE END EFP */ #ifdef __cplusplus } #endif #endif /* __STM32U5xx_IT_H */
YifuLiu/AliOS-Things
hardware/board/stm32u5_b_u585i_iot02a/drivers/stm32u5xx_it.h
C
apache-2.0
1,890
/** ****************************************************************************** * @file hardware/board/stm32u5_b_u585i_iot02a/startup/startup.c * @author MCD Application Team * @brief Starup for stm32u585 ****************************************************************************** * @attention * * Copyright (c) 2021 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ #include "stdio.h" #include "aos/init.h" #include <k_api.h> #include "k_config.h" #include <stdio.h> #include <stdlib.h> #include "aos/debug.h" #include <aos/kernel.h> #include "stm32u5xx_hal.h" /* * If enable this macro for local test, we don't use wifi service to trigger connection, * remember to mask -DALIOS_WIFI_SERVICE and set -DLWIP_SUPPORT=1 in SDK. */ #if LWIP_SUPPORT #define ALIOS_BES_APP #endif #define BES_SDK 0 #define BES_WIFI_ONLY 1 #define BES_WIFI_BT 2 #define BES_WIFI_BT_MINI 3 // cut off nouse tasks #define LED2_Pin GPIO_PIN_6 #define LED2_GPIO_Port GPIOH #define LED1_Pin GPIO_PIN_7 #define LED1_GPIO_Port GPIOH /* * main task stask size(byte) */ #define OS_MAIN_TASK_STACK (32*1024) #define OS_MAIN_TASK_PRI 32 static ktask_t *g_main_task; extern void aos_maintask(void* arg); void SystemClock_Config(void); static void SystemPower_Config(void); static void MX_GPIO_Init(void); static void MX_ICACHE_Init(void); static void MX_USART1_UART_Init(void); #ifdef STM32U5_CONFIG_MICROSPEECH static void MX_ADF1_Init(void); MDF_HandleTypeDef AdfHandle0; MDF_FilterConfigTypeDef AdfFilterConfig0; #endif //STM32U5_CONFIG_MICROSPEECH UART_HandleTypeDef huart1; #if defined ( __GNUC__) && !defined(__clang__) /* With GCC, small printf (option LD Linker->Libraries->Small printf set to 'Yes') calls __io_putchar() */ #define PUTCHAR_PROTOTYPE int __io_putchar(int ch) #else #define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f) #endif /* __GNUC__ */ int main(int argc, char *argv[]) { aos_status_t status; /* maybe other board level init */ /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ board_basic_init(); HAL_Init(); /* USER CODE BEGIN Init */ /* USER CODE END Init */ /* Configure the system clock */ SystemClock_Config(); /* Configure the System Power */ SystemPower_Config(); /* USER CODE BEGIN SysInit */ /* USER CODE END SysInit */ /* Initialize all configured peripherals */ MX_GPIO_Init(); MX_ICACHE_Init(); MX_USART1_UART_Init(); /* USER CODE BEGIN 2 */ /* kernel init, malloc can use after this! */ // HAL_SuspendTick(); #ifdef STM32U5_CONFIG_MICROSPEECH MX_ADF1_Init(); if (HAL_MDF_AcqStart(&AdfHandle0, &AdfFilterConfig0) != HAL_OK) { Error_Handler(); } #endif //STM32U5_CONFIG_MICROSPEECH aos_init(); /* main task to run */ aos_task_create(&g_main_task, "main_task", aos_maintask, NULL, NULL, OS_MAIN_TASK_STACK, OS_MAIN_TASK_PRI, 1u); /* kernel start schedule! */ aos_start(); /* never run here */ return 0; } static void MX_USART1_UART_Init(void) { /* USER CODE BEGIN USART1_Init 0 */ /* USER CODE END USART1_Init 0 */ /* USER CODE BEGIN USART1_Init 1 */ /* USER CODE END USART1_Init 1 */ huart1.Instance = USART1; huart1.Init.BaudRate = 115200; huart1.Init.WordLength = UART_WORDLENGTH_8B; huart1.Init.StopBits = UART_STOPBITS_1; huart1.Init.Parity = UART_PARITY_NONE; huart1.Init.Mode = UART_MODE_TX_RX; huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE; huart1.Init.OverSampling = UART_OVERSAMPLING_16; huart1.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE; huart1.Init.ClockPrescaler = UART_PRESCALER_DIV1; huart1.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT; if (HAL_UART_Init(&huart1) != HAL_OK) { Error_Handler(); } if (HAL_UARTEx_SetTxFifoThreshold(&huart1, UART_TXFIFO_THRESHOLD_1_8) != HAL_OK) { Error_Handler(); } if (HAL_UARTEx_SetRxFifoThreshold(&huart1, UART_RXFIFO_THRESHOLD_1_8) != HAL_OK) { Error_Handler(); } if (HAL_UARTEx_DisableFifoMode(&huart1) != HAL_OK) { Error_Handler(); } /* USER CODE BEGIN USART1_Init 2 */ /* USER CODE END USART1_Init 2 */ } void SystemClock_Config(void) { RCC_OscInitTypeDef RCC_OscInitStruct = {0}; RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; /** Configure the main internal regulator output voltage */ if (HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1) != HAL_OK) { Error_Handler(); } /** Initializes the CPU, AHB and APB busses clocks */ RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_MSI; RCC_OscInitStruct.MSIState = RCC_MSI_ON; RCC_OscInitStruct.MSICalibrationValue = RCC_MSICALIBRATION_DEFAULT; RCC_OscInitStruct.MSIClockRange = RCC_MSIRANGE_4; RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_MSI; RCC_OscInitStruct.PLL.PLLMBOOST = RCC_PLLMBOOST_DIV1; RCC_OscInitStruct.PLL.PLLM = 1; RCC_OscInitStruct.PLL.PLLN = 80; RCC_OscInitStruct.PLL.PLLP = 2; RCC_OscInitStruct.PLL.PLLQ = 2; RCC_OscInitStruct.PLL.PLLR = 2; RCC_OscInitStruct.PLL.PLLRGE = RCC_PLLVCIRANGE_0; RCC_OscInitStruct.PLL.PLLFRACN = 0; if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) { Error_Handler(); } /** Initializes the CPU, AHB and APB busses clocks */ RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2 |RCC_CLOCKTYPE_PCLK3; RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1; RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; RCC_ClkInitStruct.APB3CLKDivider = RCC_HCLK_DIV1; if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_4) != HAL_OK) { Error_Handler(); } } /** * @brief Power Configuration * @retval None */ static void SystemPower_Config(void) { /* * Disable the internal Pull-Up in Dead Battery pins of UCPD peripheral */ HAL_PWREx_DisableUCPDDeadBattery(); /* * Switch to SMPS regulator instead of LDO */ if (HAL_PWREx_ConfigSupply(PWR_SMPS_SUPPLY) != HAL_OK) { Error_Handler(); } } /** * @brief ICACHE Initialization Function * @param None * @retval None */ static void MX_ICACHE_Init(void) { /* USER CODE BEGIN ICACHE_Init 0 */ /* USER CODE END ICACHE_Init 0 */ /* USER CODE BEGIN ICACHE_Init 1 */ /* USER CODE END ICACHE_Init 1 */ /** Enable instruction cache in 1-way (direct mapped cache) */ if (HAL_ICACHE_ConfigAssociativityMode(ICACHE_1WAY) != HAL_OK) { Error_Handler(); } if (HAL_ICACHE_Enable() != HAL_OK) { Error_Handler(); } /* USER CODE BEGIN ICACHE_Init 2 */ /* USER CODE END ICACHE_Init 2 */ } /** * @brief GPIO Initialization Function * @param None * @retval None */ static void MX_GPIO_Init(void) { GPIO_InitTypeDef GPIO_InitStruct = {0}; /* GPIO Ports Clock Enable */ __HAL_RCC_GPIOH_CLK_ENABLE(); __HAL_RCC_GPIOA_CLK_ENABLE(); /*Configure GPIO pin Output Level */ HAL_GPIO_WritePin(GPIOH, LED2_Pin, GPIO_PIN_SET); HAL_GPIO_WritePin(GPIOH, LED1_Pin, GPIO_PIN_RESET); /*Configure GPIO pins : LED2_Pin LED1_Pin */ GPIO_InitStruct.Pin = LED2_Pin|LED1_Pin; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; HAL_GPIO_Init(GPIOH, &GPIO_InitStruct); HAL_GPIO_WritePin(GPIOH, LED2_Pin, GPIO_PIN_SET); HAL_GPIO_WritePin(GPIOH, LED1_Pin, GPIO_PIN_RESET); } /* USER CODE BEGIN 4 */ /* USER CODE END 4 */ /** * @brief This function is executed in case of error occurrence. * @retval None */ void Error_Handler(void) { /* USER CODE BEGIN Error_Handler_Debug */ __disable_irq(); HAL_GPIO_WritePin(LED1_GPIO_Port, LED1_Pin, GPIO_PIN_SET); while (1) { HAL_GPIO_TogglePin(LED2_GPIO_Port, LED2_Pin); HAL_Delay(1000); } /* USER CODE END Error_Handler_Debug */ } #ifdef STM32U5_CONFIG_MICROSPEECH /** * @brief ADF1 Initialization Function * @param None * @retval None */ static void MX_ADF1_Init(void) { /* USER CODE BEGIN ADF1_Init 0 */ /* USER CODE END ADF1_Init 0 */ /* USER CODE BEGIN ADF1_Init 1 */ /* USER CODE END ADF1_Init 1 */ /** AdfHandle0 structure initialization and HAL_MDF_Init function call */ AdfHandle0.Instance = ADF1_Filter0; AdfHandle0.Init.CommonParam.ProcClockDivider = 1; AdfHandle0.Init.CommonParam.OutputClock.Activation = ENABLE; AdfHandle0.Init.CommonParam.OutputClock.Pins = MDF_OUTPUT_CLOCK_0; AdfHandle0.Init.CommonParam.OutputClock.Divider = 4; AdfHandle0.Init.CommonParam.OutputClock.Trigger.Activation = DISABLE; AdfHandle0.Init.SerialInterface.Activation = ENABLE; AdfHandle0.Init.SerialInterface.Mode = MDF_SITF_NORMAL_SPI_MODE; AdfHandle0.Init.SerialInterface.ClockSource = MDF_SITF_CCK0_SOURCE; AdfHandle0.Init.SerialInterface.Threshold = 31; AdfHandle0.Init.FilterBistream = MDF_BITSTREAM0_FALLING; if (HAL_MDF_Init(&AdfHandle0) != HAL_OK) { Error_Handler(); } /** AdfFilterConfig0 structure initialization WARNING : only structure is filled, no specific init function call for filter */ AdfFilterConfig0.DataSource = MDF_DATA_SOURCE_BSMX; AdfFilterConfig0.Delay = 0; AdfFilterConfig0.CicMode = MDF_ONE_FILTER_SINC4; AdfFilterConfig0.DecimationRatio = 64; AdfFilterConfig0.Gain = 0; AdfFilterConfig0.ReshapeFilter.Activation = DISABLE; AdfFilterConfig0.HighPassFilter.Activation = DISABLE; AdfFilterConfig0.SoundActivity.Activation = ENABLE; AdfFilterConfig0.SoundActivity.Mode = MDF_SAD_VOICE_ACTIVITY_DETECTOR; AdfFilterConfig0.SoundActivity.FrameSize = MDF_SAD_8_PCM_SAMPLES; AdfFilterConfig0.SoundActivity.Hysteresis = DISABLE; AdfFilterConfig0.SoundActivity.SoundTriggerEvent = MDF_SAD_ENTER_DETECT; AdfFilterConfig0.SoundActivity.DataMemoryTransfer = MDF_SAD_MEMORY_TRANSFER_ALWAYS; AdfFilterConfig0.SoundActivity.MinNoiseLevel = 200; AdfFilterConfig0.SoundActivity.HangoverWindow = MDF_SAD_HANGOVER_4_FRAMES; AdfFilterConfig0.SoundActivity.LearningFrames = MDF_SAD_LEARNING_2_FRAMES; AdfFilterConfig0.SoundActivity.AmbientNoiseSlope = 0; AdfFilterConfig0.SoundActivity.SignalNoiseThreshold = MDF_SAD_SIGNAL_NOISE_18DB; AdfFilterConfig0.SoundActivity.SoundLevelInterrupt = DISABLE; AdfFilterConfig0.AcquisitionMode = MDF_MODE_ASYNC_CONT; AdfFilterConfig0.FifoThreshold = MDF_FIFO_THRESHOLD_NOT_EMPTY; AdfFilterConfig0.DiscardSamples = 0; /* USER CODE BEGIN ADF1_Init 2 */ /* USER CODE END ADF1_Init 2 */ } #endif //STM32U5_CONFIG_MICROSPEECH #ifdef USE_FULL_ASSERT /** * @brief Reports the name of the source file and the source line number * where the assert_param error has occurred. * @param file: pointer to the source file name * @param line: assert_param error line source number * @retval None */ void assert_failed(uint8_t *file, uint32_t line) { /* USER CODE BEGIN 6 */ /* User can add his own implementation to report the file name and line number, ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ /* Infinite loop */ while(1) { } /* USER CODE END 6 */ } #endif /* USE_FULL_ASSERT */ // // PUTCHAR_PROTOTYPE // // { // // /* Place your implementation of fputc here */ // // /* e.g. write a character to the USART1 and Loop until the end of transmission */ // // HAL_UART_Transmit(&huart1, (uint8_t *)&ch, 1, 0xFFFF); // // return ch; // // } // #ifdef __GNUC__ // int _write(int fd, char *ptr, int len) // { // for (int i = 0; i < len; i++) { // HAL_UART_Transmit(&huart1, (uint8_t*)ptr, 1, 0xFFFF); // } // return len; // } // #endif
YifuLiu/AliOS-Things
hardware/board/stm32u5_b_u585i_iot02a/startup/startup.c
C
apache-2.0
12,057
/** ****************************************************************************** * @file startup_stm32u585xx.s * @author MCD Application Team * @brief STM32U585xx devices vector table GCC toolchain. * This module performs: * - Set the initial SP * - Set the initial PC == Reset_Handler, * - Set the vector table entries with the exceptions ISR address, * - Configure the clock system * - Branches to main in the C library (which eventually * calls main()). * After Reset the Cortex-M33 processor is in Thread mode, * priority is Privileged, and the Stack is set to Main. ******************************************************************************* * @attention * * Copyright (c) 2021 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ******************************************************************************* */ .syntax unified .cpu cortex-m33 .fpu softvfp .thumb .global g_pfnVectors .global Default_Handler /* start address for the initialization values of the .data section. defined in linker script */ .word _sidata /* start address for the .data section. defined in linker script */ .word _sdata /* end address for the .data section. defined in linker script */ .word _edata /* start address for the .bss section. defined in linker script */ .word _sbss /* end address for the .bss section. defined in linker script */ .word _ebss .equ BootRAM, 0xF1E0F85F /** * @brief This is the code that gets called when the processor first * starts execution following a reset event. Only the absolutely * necessary set is performed, after which the application * supplied main() routine is called. * @param None * @retval : None */ .section .text.Reset_Handler .weak Reset_Handler .type Reset_Handler, %function Reset_Handler: ldr sp, =_estack /* set stack pointer */ /* Copy the data segment initializers from flash to SRAM */ movs r1, #0 b LoopCopyDataInit CopyDataInit: ldr r3, =_sidata ldr r3, [r3, r1] str r3, [r0, r1] adds r1, r1, #4 LoopCopyDataInit: ldr r0, =_sdata ldr r3, =_edata adds r2, r0, r1 cmp r2, r3 bcc CopyDataInit ldr r2, =_sbss b LoopFillZerobss /* Zero fill the bss segment. */ FillZerobss: movs r3, #0 str r3, [r2], #4 LoopFillZerobss: ldr r3, = _ebss cmp r2, r3 bcc FillZerobss /* Call the clock system initialization function.*/ bl SystemInit /* Call static constructors */ @ bl __libc_init_array /* Call the application's entry point.*/ bl main LoopForever: b LoopForever .size Reset_Handler, .-Reset_Handler /** * @brief This is the code that gets called when the processor receives an * unexpected interrupt. This simply enters an infinite loop, preserving * the system state for examination by a debugger. * * @param None * @retval : None */ .section .text.Default_Handler,"ax",%progbits Default_Handler: Infinite_Loop: b Infinite_Loop .size Default_Handler, .-Default_Handler /****************************************************************************** * * The minimal vector table for a Cortex-M33. Note that the proper constructs * must be placed on this to ensure that it ends up at physical address * 0x0000.0000. * ******************************************************************************/ .section .isr_vector,"a",%progbits .type g_pfnVectors, %object .size g_pfnVectors, .-g_pfnVectors g_pfnVectors: .word _estack .word Reset_Handler .word NMI_Handler .word HardFault_Handler .word MemManage_Handler .word BusFault_Handler .word UsageFault_Handler .word SecureFault_Handler .word 0 .word 0 .word 0 .word SVC_Handler .word DebugMon_Handler .word 0 .word PendSV_Handler .word SysTick_Handler .word WWDG_IRQHandler .word PVD_PVM_IRQHandler .word RTC_IRQHandler .word RTC_S_IRQHandler .word TAMP_IRQHandler .word RAMCFG_IRQHandler .word FLASH_IRQHandler .word FLASH_S_IRQHandler .word GTZC_IRQHandler .word RCC_IRQHandler .word RCC_S_IRQHandler .word EXTI0_IRQHandler .word EXTI1_IRQHandler .word EXTI2_IRQHandler .word EXTI3_IRQHandler .word EXTI4_IRQHandler .word EXTI5_IRQHandler .word EXTI6_IRQHandler .word EXTI7_IRQHandler .word EXTI8_IRQHandler .word EXTI9_IRQHandler .word EXTI10_IRQHandler .word EXTI11_IRQHandler .word EXTI12_IRQHandler .word EXTI13_IRQHandler .word EXTI14_IRQHandler .word EXTI15_IRQHandler .word IWDG_IRQHandler .word SAES_IRQHandler .word GPDMA1_Channel0_IRQHandler .word GPDMA1_Channel1_IRQHandler .word GPDMA1_Channel2_IRQHandler .word GPDMA1_Channel3_IRQHandler .word GPDMA1_Channel4_IRQHandler .word GPDMA1_Channel5_IRQHandler .word GPDMA1_Channel6_IRQHandler .word GPDMA1_Channel7_IRQHandler .word ADC1_IRQHandler .word DAC1_IRQHandler .word FDCAN1_IT0_IRQHandler .word FDCAN1_IT1_IRQHandler .word TIM1_BRK_IRQHandler .word TIM1_UP_IRQHandler .word TIM1_TRG_COM_IRQHandler .word TIM1_CC_IRQHandler .word TIM2_IRQHandler .word TIM3_IRQHandler .word TIM4_IRQHandler .word TIM5_IRQHandler .word TIM6_IRQHandler .word TIM7_IRQHandler .word TIM8_BRK_IRQHandler .word TIM8_UP_IRQHandler .word TIM8_TRG_COM_IRQHandler .word TIM8_CC_IRQHandler .word I2C1_EV_IRQHandler .word I2C1_ER_IRQHandler .word I2C2_EV_IRQHandler .word I2C2_ER_IRQHandler .word SPI1_IRQHandler .word SPI2_IRQHandler .word USART1_IRQHandler .word USART2_IRQHandler .word USART3_IRQHandler .word UART4_IRQHandler .word UART5_IRQHandler .word LPUART1_IRQHandler .word LPTIM1_IRQHandler .word LPTIM2_IRQHandler .word TIM15_IRQHandler .word TIM16_IRQHandler .word TIM17_IRQHandler .word COMP_IRQHandler .word OTG_FS_IRQHandler .word CRS_IRQHandler .word FMC_IRQHandler .word OCTOSPI1_IRQHandler .word PWR_S3WU_IRQHandler .word SDMMC1_IRQHandler .word SDMMC2_IRQHandler .word GPDMA1_Channel8_IRQHandler .word GPDMA1_Channel9_IRQHandler .word GPDMA1_Channel10_IRQHandler .word GPDMA1_Channel11_IRQHandler .word GPDMA1_Channel12_IRQHandler .word GPDMA1_Channel13_IRQHandler .word GPDMA1_Channel14_IRQHandler .word GPDMA1_Channel15_IRQHandler .word I2C3_EV_IRQHandler .word I2C3_ER_IRQHandler .word SAI1_IRQHandler .word SAI2_IRQHandler .word TSC_IRQHandler .word AES_IRQHandler .word RNG_IRQHandler .word FPU_IRQHandler .word HASH_IRQHandler .word PKA_IRQHandler .word LPTIM3_IRQHandler .word SPI3_IRQHandler .word I2C4_ER_IRQHandler .word I2C4_EV_IRQHandler .word MDF1_FLT0_IRQHandler .word MDF1_FLT1_IRQHandler .word MDF1_FLT2_IRQHandler .word MDF1_FLT3_IRQHandler .word UCPD1_IRQHandler .word ICACHE_IRQHandler .word OTFDEC1_IRQHandler .word OTFDEC2_IRQHandler .word LPTIM4_IRQHandler .word DCACHE1_IRQHandler .word ADF1_IRQHandler .word ADC4_IRQHandler .word LPDMA1_Channel0_IRQHandler .word LPDMA1_Channel1_IRQHandler .word LPDMA1_Channel2_IRQHandler .word LPDMA1_Channel3_IRQHandler .word DMA2D_IRQHandler .word DCMI_PSSI_IRQHandler .word OCTOSPI2_IRQHandler .word MDF1_FLT4_IRQHandler .word MDF1_FLT5_IRQHandler .word CORDIC_IRQHandler .word FMAC_IRQHandler /******************************************************************************* * * Provide weak aliases for each Exception handler to the Default_Handler. * As they are weak aliases, any function with the same name will override * this definition. * *******************************************************************************/ .weak NMI_Handler .thumb_set NMI_Handler,Default_Handler .weak HardFault_Handler .thumb_set HardFault_Handler,Default_Handler .weak MemManage_Handler .thumb_set MemManage_Handler,Default_Handler .weak BusFault_Handler .thumb_set BusFault_Handler,Default_Handler .weak UsageFault_Handler .thumb_set UsageFault_Handler,Default_Handler .weak SecureFault_Handler .thumb_set SecureFault_Handler,Default_Handler .weak SVC_Handler .thumb_set SVC_Handler,Default_Handler .weak DebugMon_Handler .thumb_set DebugMon_Handler,Default_Handler .weak PendSV_Handler .thumb_set PendSV_Handler,Default_Handler .weak SysTick_Handler .thumb_set SysTick_Handler,Default_Handler .weak WWDG_IRQHandler .thumb_set WWDG_IRQHandler,Default_Handler .weak PVD_PVM_IRQHandler .thumb_set PVD_PVM_IRQHandler,Default_Handler .weak RTC_IRQHandler .thumb_set RTC_IRQHandler,Default_Handler .weak RTC_S_IRQHandler .thumb_set RTC_S_IRQHandler,Default_Handler .weak TAMP_IRQHandler .thumb_set TAMP_IRQHandler,Default_Handler .weak RAMCFG_IRQHandler .thumb_set RAMCFG_IRQHandler,Default_Handler .weak FLASH_IRQHandler .thumb_set FLASH_IRQHandler,Default_Handler .weak FLASH_S_IRQHandler .thumb_set FLASH_S_IRQHandler,Default_Handler .weak GTZC_IRQHandler .thumb_set GTZC_IRQHandler,Default_Handler .weak RCC_IRQHandler .thumb_set RCC_IRQHandler,Default_Handler .weak RCC_S_IRQHandler .thumb_set RCC_S_IRQHandler,Default_Handler .weak EXTI0_IRQHandler .thumb_set EXTI0_IRQHandler,Default_Handler .weak EXTI1_IRQHandler .thumb_set EXTI1_IRQHandler,Default_Handler .weak EXTI2_IRQHandler .thumb_set EXTI2_IRQHandler,Default_Handler .weak EXTI3_IRQHandler .thumb_set EXTI3_IRQHandler,Default_Handler .weak EXTI4_IRQHandler .thumb_set EXTI4_IRQHandler,Default_Handler .weak EXTI5_IRQHandler .thumb_set EXTI5_IRQHandler,Default_Handler .weak EXTI6_IRQHandler .thumb_set EXTI6_IRQHandler,Default_Handler .weak EXTI7_IRQHandler .thumb_set EXTI7_IRQHandler,Default_Handler .weak EXTI8_IRQHandler .thumb_set EXTI8_IRQHandler,Default_Handler .weak EXTI9_IRQHandler .thumb_set EXTI9_IRQHandler,Default_Handler .weak EXTI10_IRQHandler .thumb_set EXTI10_IRQHandler,Default_Handler .weak EXTI11_IRQHandler .thumb_set EXTI11_IRQHandler,Default_Handler .weak EXTI12_IRQHandler .thumb_set EXTI12_IRQHandler,Default_Handler .weak EXTI13_IRQHandler .thumb_set EXTI13_IRQHandler,Default_Handler .weak EXTI14_IRQHandler .thumb_set EXTI14_IRQHandler,Default_Handler .weak EXTI15_IRQHandler .thumb_set EXTI15_IRQHandler,Default_Handler .weak IWDG_IRQHandler .thumb_set IWDG_IRQHandler,Default_Handler .weak SAES_IRQHandler .thumb_set SAES_IRQHandler,Default_Handler .weak GPDMA1_Channel0_IRQHandler .thumb_set GPDMA1_Channel0_IRQHandler,Default_Handler .weak GPDMA1_Channel1_IRQHandler .thumb_set GPDMA1_Channel1_IRQHandler,Default_Handler .weak GPDMA1_Channel2_IRQHandler .thumb_set GPDMA1_Channel2_IRQHandler,Default_Handler .weak GPDMA1_Channel3_IRQHandler .thumb_set GPDMA1_Channel3_IRQHandler,Default_Handler .weak GPDMA1_Channel4_IRQHandler .thumb_set GPDMA1_Channel4_IRQHandler,Default_Handler .weak GPDMA1_Channel5_IRQHandler .thumb_set GPDMA1_Channel5_IRQHandler,Default_Handler .weak GPDMA1_Channel6_IRQHandler .thumb_set GPDMA1_Channel6_IRQHandler,Default_Handler .weak GPDMA1_Channel7_IRQHandler .thumb_set GPDMA1_Channel7_IRQHandler,Default_Handler .weak ADC1_IRQHandler .thumb_set ADC1_IRQHandler,Default_Handler .weak DAC1_IRQHandler .thumb_set DAC1_IRQHandler,Default_Handler .weak FDCAN1_IT0_IRQHandler .thumb_set FDCAN1_IT0_IRQHandler,Default_Handler .weak FDCAN1_IT1_IRQHandler .thumb_set FDCAN1_IT1_IRQHandler,Default_Handler .weak TIM1_BRK_IRQHandler .thumb_set TIM1_BRK_IRQHandler,Default_Handler .weak TIM1_UP_IRQHandler .thumb_set TIM1_UP_IRQHandler,Default_Handler .weak TIM1_TRG_COM_IRQHandler .thumb_set TIM1_TRG_COM_IRQHandler,Default_Handler .weak TIM1_CC_IRQHandler .thumb_set TIM1_CC_IRQHandler,Default_Handler .weak TIM2_IRQHandler .thumb_set TIM2_IRQHandler,Default_Handler .weak TIM3_IRQHandler .thumb_set TIM3_IRQHandler,Default_Handler .weak TIM4_IRQHandler .thumb_set TIM4_IRQHandler,Default_Handler .weak TIM5_IRQHandler .thumb_set TIM5_IRQHandler,Default_Handler .weak TIM6_IRQHandler .thumb_set TIM6_IRQHandler,Default_Handler .weak TIM7_IRQHandler .thumb_set TIM7_IRQHandler,Default_Handler .weak TIM8_BRK_IRQHandler .thumb_set TIM8_BRK_IRQHandler,Default_Handler .weak TIM8_UP_IRQHandler .thumb_set TIM8_UP_IRQHandler,Default_Handler .weak TIM8_TRG_COM_IRQHandler .thumb_set TIM8_TRG_COM_IRQHandler,Default_Handler .weak TIM8_CC_IRQHandler .thumb_set TIM8_CC_IRQHandler,Default_Handler .weak I2C1_EV_IRQHandler .thumb_set I2C1_EV_IRQHandler,Default_Handler .weak I2C1_ER_IRQHandler .thumb_set I2C1_ER_IRQHandler,Default_Handler .weak I2C2_EV_IRQHandler .thumb_set I2C2_EV_IRQHandler,Default_Handler .weak I2C2_ER_IRQHandler .thumb_set I2C2_ER_IRQHandler,Default_Handler .weak SPI1_IRQHandler .thumb_set SPI1_IRQHandler,Default_Handler .weak SPI2_IRQHandler .thumb_set SPI2_IRQHandler,Default_Handler .weak USART1_IRQHandler .thumb_set USART1_IRQHandler,Default_Handler .weak USART2_IRQHandler .thumb_set USART2_IRQHandler,Default_Handler .weak USART3_IRQHandler .thumb_set USART3_IRQHandler,Default_Handler .weak UART4_IRQHandler .thumb_set UART4_IRQHandler,Default_Handler .weak UART5_IRQHandler .thumb_set UART5_IRQHandler,Default_Handler .weak LPUART1_IRQHandler .thumb_set LPUART1_IRQHandler,Default_Handler .weak LPTIM1_IRQHandler .thumb_set LPTIM1_IRQHandler,Default_Handler .weak LPTIM2_IRQHandler .thumb_set LPTIM2_IRQHandler,Default_Handler .weak TIM15_IRQHandler .thumb_set TIM15_IRQHandler,Default_Handler .weak TIM16_IRQHandler .thumb_set TIM16_IRQHandler,Default_Handler .weak TIM17_IRQHandler .thumb_set TIM17_IRQHandler,Default_Handler .weak COMP_IRQHandler .thumb_set COMP_IRQHandler,Default_Handler .weak OTG_FS_IRQHandler .thumb_set OTG_FS_IRQHandler,Default_Handler .weak CRS_IRQHandler .thumb_set CRS_IRQHandler,Default_Handler .weak FMC_IRQHandler .thumb_set FMC_IRQHandler,Default_Handler .weak OCTOSPI1_IRQHandler .thumb_set OCTOSPI1_IRQHandler,Default_Handler .weak PWR_S3WU_IRQHandler .thumb_set PWR_S3WU_IRQHandler,Default_Handler .weak SDMMC1_IRQHandler .thumb_set SDMMC1_IRQHandler,Default_Handler .weak SDMMC2_IRQHandler .thumb_set SDMMC2_IRQHandler,Default_Handler .weak GPDMA1_Channel8_IRQHandler .thumb_set GPDMA1_Channel8_IRQHandler,Default_Handler .weak GPDMA1_Channel9_IRQHandler .thumb_set GPDMA1_Channel9_IRQHandler,Default_Handler .weak GPDMA1_Channel10_IRQHandler .thumb_set GPDMA1_Channel10_IRQHandler,Default_Handler .weak GPDMA1_Channel11_IRQHandler .thumb_set GPDMA1_Channel11_IRQHandler,Default_Handler .weak GPDMA1_Channel12_IRQHandler .thumb_set GPDMA1_Channel12_IRQHandler,Default_Handler .weak GPDMA1_Channel13_IRQHandler .thumb_set GPDMA1_Channel13_IRQHandler,Default_Handler .weak GPDMA1_Channel14_IRQHandler .thumb_set GPDMA1_Channel14_IRQHandler,Default_Handler .weak GPDMA1_Channel15_IRQHandler .thumb_set GPDMA1_Channel15_IRQHandler,Default_Handler .weak I2C3_EV_IRQHandler .thumb_set I2C3_EV_IRQHandler,Default_Handler .weak I2C3_ER_IRQHandler .thumb_set I2C3_ER_IRQHandler,Default_Handler .weak SAI1_IRQHandler .thumb_set SAI1_IRQHandler,Default_Handler .weak SAI2_IRQHandler .thumb_set SAI2_IRQHandler,Default_Handler .weak TSC_IRQHandler .thumb_set TSC_IRQHandler,Default_Handler .weak AES_IRQHandler .thumb_set AES_IRQHandler,Default_Handler .weak RNG_IRQHandler .thumb_set RNG_IRQHandler,Default_Handler .weak FPU_IRQHandler .thumb_set FPU_IRQHandler,Default_Handler .weak HASH_IRQHandler .thumb_set HASH_IRQHandler,Default_Handler .weak PKA_IRQHandler .thumb_set PKA_IRQHandler,Default_Handler .weak LPTIM3_IRQHandler .thumb_set LPTIM3_IRQHandler,Default_Handler .weak SPI3_IRQHandler .thumb_set SPI3_IRQHandler,Default_Handler .weak I2C4_ER_IRQHandler .thumb_set I2C4_ER_IRQHandler,Default_Handler .weak I2C4_EV_IRQHandler .thumb_set I2C4_EV_IRQHandler,Default_Handler .weak MDF1_FLT0_IRQHandler .thumb_set MDF1_FLT0_IRQHandler,Default_Handler .weak MDF1_FLT1_IRQHandler .thumb_set MDF1_FLT1_IRQHandler,Default_Handler .weak MDF1_FLT2_IRQHandler .thumb_set MDF1_FLT2_IRQHandler,Default_Handler .weak MDF1_FLT3_IRQHandler .thumb_set MDF1_FLT3_IRQHandler,Default_Handler .weak UCPD1_IRQHandler .thumb_set UCPD1_IRQHandler,Default_Handler .weak ICACHE_IRQHandler .thumb_set ICACHE_IRQHandler,Default_Handler .weak OTFDEC1_IRQHandler .thumb_set OTFDEC1_IRQHandler,Default_Handler .weak OTFDEC2_IRQHandler .thumb_set OTFDEC2_IRQHandler,Default_Handler .weak LPTIM4_IRQHandler .thumb_set LPTIM4_IRQHandler,Default_Handler .weak DCACHE1_IRQHandler .thumb_set DCACHE1_IRQHandler,Default_Handler .weak ADF1_IRQHandler .thumb_set ADF1_IRQHandler,Default_Handler .weak ADC4_IRQHandler .thumb_set ADC4_IRQHandler,Default_Handler .weak LPDMA1_Channel0_IRQHandler .thumb_set LPDMA1_Channel0_IRQHandler,Default_Handler .weak LPDMA1_Channel1_IRQHandler .thumb_set LPDMA1_Channel1_IRQHandler,Default_Handler .weak LPDMA1_Channel2_IRQHandler .thumb_set LPDMA1_Channel2_IRQHandler,Default_Handler .weak LPDMA1_Channel3_IRQHandler .thumb_set LPDMA1_Channel3_IRQHandler,Default_Handler .weak DMA2D_IRQHandler .thumb_set DMA2D_IRQHandler,Default_Handler .weak DCMI_PSSI_IRQHandler .thumb_set DCMI_PSSI_IRQHandler,Default_Handler .weak OCTOSPI2_IRQHandler .thumb_set OCTOSPI2_IRQHandler,Default_Handler .weak MDF1_FLT4_IRQHandler .thumb_set MDF1_FLT4_IRQHandler,Default_Handler .weak MDF1_FLT5_IRQHandler .thumb_set MDF1_FLT5_IRQHandler,Default_Handler .weak CORDIC_IRQHandler .thumb_set CORDIC_IRQHandler,Default_Handler .weak FMAC_IRQHandler .thumb_set FMAC_IRQHandler,Default_Handler
YifuLiu/AliOS-Things
hardware/board/stm32u5_b_u585i_iot02a/startup/startup_gcc.s
Unix Assembly
apache-2.0
17,737
set(COMPONENT_ADD_INCLUDEDIRS cloud_services/include include) # Edit following two lines to set component requirements (see docs) set(COMPONENT_PRIV_REQUIRES esp_http_client jsmn mbedtls audio_sal) set(COMPONENT_SRCS ./json_utils.c cloud_services/aws_sig_v4_signing.c cloud_services/baidu_access_token.c) register_component()
YifuLiu/AliOS-Things
hardware/chip/espressif_adf/esp-adf/components/adf_utils/CMakeLists.txt
CMake
apache-2.0
329
/* * ESPRESSIF MIT License * * Copyright (c) 2018 <ESPRESSIF SYSTEMS (SHANGHAI) PTE LTD> * * Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case, * it is free of charge, to any person obtaining a copy of this software and associated * documentation files (the "Software"), to deal in the Software without restriction, including * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the Software is furnished * to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all copies or * substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * */ #include <stdlib.h> #include <string.h> #include <stdio.h> #include <stdarg.h> #include "freertos/FreeRTOS.h" #include "aws_sig_v4_signing.h" #define HASH_LENGHT (32) #define HASH_HEX_LENGTH (65) static const char *aws_algorithm = "AWS4-HMAC-SHA256"; #define GET_BUFFER(ctx) (ctx->buffer + ctx->buffer_offset) #define NEXT_BUFFER(ctx, len) (ctx->buffer_offset += len) #define REMAIN_BUFFER(ctx) (AWS_SIG_V4_BUFFER_SIZE - ctx->buffer_offset) static void _hmac(char *output, const char *key, int key_size, const char *payload, int payload_size) { mbedtls_md_context_t ctx; mbedtls_md_init(&ctx); mbedtls_md_setup(&ctx, mbedtls_md_info_from_type(MBEDTLS_MD_SHA256), 1); mbedtls_md_hmac_starts(&ctx, (const unsigned char *) key, key_size); mbedtls_md_hmac_update(&ctx, (const unsigned char *) payload, payload_size); mbedtls_md_hmac_finish(&ctx, (unsigned char *)output); mbedtls_md_free(&ctx); } static void _hmac_hex(char *output, const char *key, int key_size, const char *payload, int payload_size) { char hmac[HASH_LENGHT]; _hmac(hmac, key, key_size, payload, payload_size); for (int i = 0; i < sizeof(hmac); i++) { sprintf(output + i * 2, "%02x", (int)hmac[i]); } output[HASH_HEX_LENGTH - 1] = 0; } static void _sha256_hex(char *output, const char *data, int data_len) { char sha256_res[HASH_LENGHT]; mbedtls_sha256_context ctx; mbedtls_sha256_init(&ctx); mbedtls_sha256_starts(&ctx, 0); /* SHA-256, not 224 */ mbedtls_sha256_update(&ctx, (const unsigned char*)data, data_len); mbedtls_sha256_finish(&ctx, (unsigned char *)sha256_res); mbedtls_sha256_free(&ctx); for (int i = 0; i < sizeof(sha256_res); i++) { sprintf(output + i * 2, "%02x", (int)sha256_res[i]); } output[HASH_HEX_LENGTH - 1] = 0; } static void _get_signature_key(char *output, const char *aws4_key, const char *date_stamp, const char *region_name, const char *service_name) { char k_date[HASH_LENGHT], k_region[HASH_LENGHT], k_service[HASH_LENGHT]; _hmac(k_date, aws4_key, strlen(aws4_key), date_stamp, strlen(date_stamp)); _hmac(k_region, k_date, HASH_LENGHT, region_name, strlen(region_name)); _hmac(k_service, k_region, HASH_LENGHT, service_name, strlen(service_name)); _hmac(output, k_service, HASH_LENGHT, "aws4_request", strlen("aws4_request")); } char *aws_sig_v4_signing_header(aws_sig_v4_context_t *ctx, aws_sig_v4_config_t *config) { memset(ctx, 0, sizeof(aws_sig_v4_context_t)); char *payload_hash = GET_BUFFER(ctx); _sha256_hex(payload_hash, config->payload, config->payload_len); NEXT_BUFFER(ctx, HASH_HEX_LENGTH); char *canonical_request = GET_BUFFER(ctx); char separate = config->signed_headers && strlen(config->signed_headers) > 0 ? ';' : 0; int canonical_request_len = snprintf(canonical_request, REMAIN_BUFFER(ctx), "%s\n%s\n%s\n%shost:%s\nx-amz-date:%s\n\n%s%chost;x-amz-date\n%s", config->method, config->path, config->query, config->canonical_headers, config->host, config->amz_date, config->signed_headers, separate, payload_hash); NEXT_BUFFER(ctx, canonical_request_len + 1); char *canonical_request_sha256 = GET_BUFFER(ctx); _sha256_hex(canonical_request_sha256, canonical_request, canonical_request_len); NEXT_BUFFER(ctx, HASH_HEX_LENGTH); char *credential_scope = GET_BUFFER(ctx); int credential_scope_len = snprintf(credential_scope, REMAIN_BUFFER(ctx), "%s/%s/%s/aws4_request", config->date_stamp, config->region_name, config->service_name); NEXT_BUFFER(ctx, credential_scope_len + 1); char *aws4_key = GET_BUFFER(ctx); int aws4_key_len = snprintf(aws4_key, REMAIN_BUFFER(ctx), "AWS4%s", config->secret_key); NEXT_BUFFER(ctx, aws4_key_len); char *signing_key = GET_BUFFER(ctx); _get_signature_key(signing_key, aws4_key, config->date_stamp, config->region_name, config->service_name); NEXT_BUFFER(ctx, HASH_LENGHT); char *string_to_sign = GET_BUFFER(ctx); int string_to_sign_len = snprintf(string_to_sign, REMAIN_BUFFER(ctx), "%s\n%s\n%s\n%s", aws_algorithm, config->amz_date, credential_scope, canonical_request_sha256); NEXT_BUFFER(ctx, string_to_sign_len + 1); char *signature = GET_BUFFER(ctx); _hmac_hex(signature, signing_key, HASH_LENGHT, string_to_sign, string_to_sign_len); NEXT_BUFFER(ctx, HASH_HEX_LENGTH); char *authorization_header = GET_BUFFER(ctx); snprintf(authorization_header, REMAIN_BUFFER(ctx), "%s Credential=%s/%s, SignedHeaders=%s%chost;x-amz-date, Signature=%s", aws_algorithm, config->access_key, credential_scope, config->signed_headers, separate, signature); return authorization_header; }
YifuLiu/AliOS-Things
hardware/chip/espressif_adf/esp-adf/components/adf_utils/cloud_services/aws_sig_v4_signing.c
C
apache-2.0
6,984
/* * ESPRESSIF MIT License * * Copyright (c) 2018 <ESPRESSIF SYSTEMS (SHANGHAI) PTE LTD> * * Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case, * it is free of charge, to any person obtaining a copy of this software and associated * documentation files (the "Software"), to deal in the Software without restriction, including * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the Software is furnished * to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all copies or * substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * */ #include <string.h> #include <stdlib.h> #include "esp_http_client.h" #include "json_utils.h" #include "esp_log.h" #include "audio_error.h" #define BAIDU_URI_LENGTH (200) #define BAIDU_AUTH_ENDPOINT "https://openapi.baidu.com/oauth/2.0/token?grant_type=client_credentials" static const char *TAG = "BAIDU_AUTH"; char *baidu_get_access_token(const char *access_key, const char *access_secret) { char *token = NULL; char *url = calloc(1, BAIDU_URI_LENGTH); AUDIO_MEM_CHECK(TAG, url, return NULL); snprintf(url, BAIDU_URI_LENGTH, BAIDU_AUTH_ENDPOINT"&client_id=%s&client_secret=%s", access_key, access_secret); esp_http_client_config_t config = { .url = url, }; esp_http_client_handle_t http_client = esp_http_client_init(&config); AUDIO_MEM_CHECK(TAG, http_client, return NULL); if (esp_http_client_open(http_client, 0) != ESP_OK) { ESP_LOGE(TAG, "Error open http request to baidu auth server"); goto _exit; } esp_http_client_fetch_headers(http_client); int max_len = 2 * 1024; char *data = malloc(max_len); AUDIO_MEM_CHECK(TAG, data, goto _exit); int read_index = 0, total_len = 0; while (1) { int read_len = esp_http_client_read(http_client, data + read_index, max_len - read_index); if (read_len <= 0) { break; } read_index += read_len; total_len += read_len; data[read_index] = 0; } if (total_len <= 0) { ESP_LOGE(TAG, "Invalid length of the response"); free(data); goto _exit; } // Remove unexpect characters ESP_LOGD(TAG, "Data=%s", data); token = json_get_token_value(data, "access_token"); free(data); if (token) { ESP_LOGI(TAG, "Access token=%s", token); } _exit: free(url); esp_http_client_close(http_client); esp_http_client_cleanup(http_client); return token; }
YifuLiu/AliOS-Things
hardware/chip/espressif_adf/esp-adf/components/adf_utils/cloud_services/baidu_access_token.c
C
apache-2.0
3,147
/* * ESPRESSIF MIT License * * Copyright (c) 2018 <ESPRESSIF SYSTEMS (SHANGHAI) PTE LTD> * * Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case, * it is free of charge, to any person obtaining a copy of this software and associated * documentation files (the "Software"), to deal in the Software without restriction, including * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the Software is furnished * to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all copies or * substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * */ #include "mbedtls/sha256.h" #include "mbedtls/md.h" #ifndef _AWS_SIG_V4_SIGNING_H_ #define _AWS_SIG_V4_SIGNING_H_ #ifdef __cplusplus extern "C" { #endif #define AWS_SIG_V4_BUFFER_SIZE (2048) /** * @brief Amazon Signature V4 signing context */ typedef struct { mbedtls_sha256_context sha256_ctx; /*!< mbedtls SHA256 context */ mbedtls_md_context_t md_ctx; /*!< mbedtls HMAC context */ char buffer[AWS_SIG_V4_BUFFER_SIZE]; /*!< Buffer to use for this library */ int buffer_offset; /*!< The buffer offset have been used */ } aws_sig_v4_context_t; /** * @brief Amazon Signature V4 signing configurations */ typedef struct { const char *service_name; /*!< AWS Service name, ex: polly */ const char *region_name; /*!< AWS Region name, ex: us-east-1 */ const char *secret_key; /*!< AWS IAM user secret key */ const char *access_key; /*!< AWS IAM user access key */ const char *host; /*!< Current request host name, ex: polly.us-east-1.amazonaws.com*/ const char *method; /*!< Current request method, ex: POST */ const char *path; /*!< Current request path, ex: "/" or "/v1/speech" */ const char *query; /*!< Current request query, ex: "" or "?key=value" */ const char *amz_date; /*!< AWS Date, format as `%Y%m%dT%H%M%SZ` */ const char *date_stamp; /*!< Datestamp, format as `%Y%m%d` */ const char *signed_headers; /*!< Singed headers */ const char *canonical_headers; /*!< Canonical headers headers */ const char *payload; /*!< Payload data */ int payload_len; /*!< Payload length */ } aws_sig_v4_config_t; /** * @brief Create HTTP Header for Amazon Signature V4 signing * * @param ctx The context * @param config The configuration * * @return The HTTP Header value of `Authorization` */ char *aws_sig_v4_signing_header(aws_sig_v4_context_t *ctx, aws_sig_v4_config_t *config); #ifdef __cplusplus } #endif #endif
YifuLiu/AliOS-Things
hardware/chip/espressif_adf/esp-adf/components/adf_utils/cloud_services/include/aws_sig_v4_signing.h
C
apache-2.0
3,456
/* * ESPRESSIF MIT License * * Copyright (c) 2018 <ESPRESSIF SYSTEMS (SHANGHAI) PTE LTD> * * Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case, * it is free of charge, to any person obtaining a copy of this software and associated * documentation files (the "Software"), to deal in the Software without restriction, including * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the Software is furnished * to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all copies or * substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * */ #ifndef _BAIDU_ACCESS_TOKEN #define _BAIDU_ACCESS_TOKEN #ifdef __cplusplus extern "C" { #endif /** * @brief Get baidu access token * * @param[in] access_key The access key * @param[in] access_secret The access secret * * @return Access token response from baidu, need to freed after used */ char *baidu_get_access_token(const char *access_key, const char *access_secret); #ifdef __cplusplus } #endif #endif
YifuLiu/AliOS-Things
hardware/chip/espressif_adf/esp-adf/components/adf_utils/cloud_services/include/baidu_access_token.h
C
apache-2.0
1,670
# https://docs.aws.amazon.com/general/latest/gr/sigv4-signed-request-examples.html import sys, os, base64, datetime, hashlib, hmac import requests # pip install requests # ************* REQUEST VALUES ************* method = 'POST' host = 'polly.us-east-1.amazonaws.com' endpoint = 'https://polly.us-east-1.amazonaws.com/v1/speech' request_parameters = '' payload_data = '{"OutputFormat":"mp3","SampleRate":"22050","Text":"Espressif Systems is a fabless semiconductor company, with headquarter in Shanghai Zhangjiang High-Tech Park, providing low power Wi-Fi and Bluetooth SoCs and wireless solutions for Internet of Things applications","TextType":"text","VoiceId":"Joanna"}' access_key = os.environ.get('AWS_ACCESS_KEY_ID') secret_key = os.environ.get('AWS_SECRET_ACCESS_KEY') region = os.environ.get('AWS_REGION') service = os.environ.get('AWS_SERVICE_NAME') amzdate = os.environ.get('AWS_DATE') datestamp = os.environ.get('DATESTAMP') user_payload = os.environ.get('PAYLOAD') # # Key derivation functions. See: # http://docs.aws.amazon.com/general/latest/gr/signature-v4-examples.html#signature-v4-examples-python def sign(key, msg): return hmac.new(key, msg.encode('utf-8'), hashlib.sha256).digest() def getSignatureKey(key, dateStamp, regionName, serviceName): kDate = sign(('AWS4' + key).encode('utf-8'), dateStamp) kRegion = sign(kDate, regionName) kService = sign(kRegion, serviceName) kSigning = sign(kService, 'aws4_request') return kSigning # Read AWS access key from env. variables or configuration file. Best practice is NOT # to embed credentials in code. if access_key is None or secret_key is None: print 'No access key is available.' sys.exit() # Create a date for headers and the credential string t = datetime.datetime.utcnow() if amzdate is None: amzdate = t.strftime('%Y%m%dT%H%M%SZ') datestamp = t.strftime('%Y%m%d') # Date w/o time, used in credential scope if region is None: region = 'us-east-1' if service is None: service = 'polly' if user_payload is not None: payload_data = user_payload # ************* TASK 1: CREATE A CANONICAL REQUEST ************* # http://docs.aws.amazon.com/general/latest/gr/sigv4-create-canonical-request.html # Step 1 is to define the verb (GET, POST, etc.)--already done. # Step 2: Create canonical URI--the part of the URI from domain to query # string (use '/' if no path) canonical_uri = '/v1/speech' # Step 3: Create the canonical query string. In this example (a GET request), # request parameters are in the query string. Query string values must # be URL-encoded (space=%20). The parameters must be sorted by name. # For this example, the query string is pre-formatted in the request_parameters variable. canonical_querystring = request_parameters # Step 4: Create the canonical headers and signed headers. Header names # must be trimmed and lowercase, and sorted in code point order from # low to high. Note that there is a trailing \n. canonical_headers = 'host:' + host + '\n' + 'x-amz-date:' + amzdate + '\n' + 'content-type:application/json\n' # Step 5: Create the list of signed headers. This lists the headers # in the canonical_headers list, delimited with ";" and in alpha order. # Note: The request can include any headers; canonical_headers and # signed_headers lists those that you want to be included in the # hash of the request. "Host" and "x-amz-date" are always required. signed_headers = 'host;x-amz-date;content-type' # Step 6: Create payload hash (hash of the request body content). For GET # requests, the payload is an empty string (""). payload_hash = hashlib.sha256(payload_data).hexdigest() # Step 7: Combine elements to create canonical request canonical_request = method + '\n' + canonical_uri + '\n' + canonical_querystring + '\n' + canonical_headers + '\n' + signed_headers + '\n' + payload_hash # ************* TASK 2: CREATE THE STRING TO SIGN************* # Match the algorithm to the hashing algorithm you use, either SHA-1 or # SHA-256 (recommended) algorithm = 'AWS4-HMAC-SHA256' credential_scope = datestamp + '/' + region + '/' + service + '/' + 'aws4_request' string_to_sign = algorithm + '\n' + amzdate + '\n' + credential_scope + '\n' + hashlib.sha256(canonical_request).hexdigest() # ************* TASK 3: CALCULATE THE SIGNATURE ************* # Create the signing key using the function defined above. signing_key = getSignatureKey(secret_key, datestamp, region, service) # Sign the string_to_sign using the signing_key signature = hmac.new(signing_key, (string_to_sign).encode('utf-8'), hashlib.sha256).hexdigest() # ************* TASK 4: ADD SIGNING INFORMATION TO THE REQUEST ************* # The signing information can be either in a query string value or in # a header named Authorization. This code shows how to use a header. # Create authorization header and add to request headers authorization_header = algorithm + ' ' + 'Credential=' + access_key + '/' + credential_scope + ', ' + 'SignedHeaders=' + signed_headers + ', ' + 'Signature=' + signature # The request can include any headers, but MUST include "host", "x-amz-date", # and (for this scenario) "Authorization". "host" and "x-amz-date" must # be included in the canonical_headers and signed_headers, as noted # earlier. Order here is not significant. # Python note: The 'host' header is added automatically by the Python 'requests' library. headers = {'x-amz-date':amzdate, 'Authorization':authorization_header} print(headers)
YifuLiu/AliOS-Things
hardware/chip/espressif_adf/esp-adf/components/adf_utils/cloud_services/test/aws_sig_v4_sign.py
Python
apache-2.0
5,527
# # "main" pseudo-component makefile. # # (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.) COMPONENT_ADD_INCLUDEDIRS := cloud_services/include include COMPONENT_SRCDIRS := . cloud_services
YifuLiu/AliOS-Things
hardware/chip/espressif_adf/esp-adf/components/adf_utils/component.mk
Makefile
apache-2.0
246
/* * ESPRESSIF MIT License * * Copyright (c) 2018 <ESPRESSIF SYSTEMS (SHANGHAI) PTE LTD> * * Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case, * it is free of charge, to any person obtaining a copy of this software and associated * documentation files (the "Software"), to deal in the Software without restriction, including * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the Software is furnished * to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all copies or * substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * */ #ifndef _JSON_UTILS_H_ #define _JSON_UTILS_H_ #ifdef __cplusplus extern "C" { #endif /** * @brief This function returns the string value of the token in json_string. * The returning string is allocated and must be free as soon as it is used * * @param[in] json_string The json string * @param[in] token_name The token name * * @return The token value */ char *json_get_token_value(const char *json_string, const char *token_name); #ifdef __cplusplus } #endif #endif
YifuLiu/AliOS-Things
hardware/chip/espressif_adf/esp-adf/components/adf_utils/include/json_utils.h
C
apache-2.0
1,739
/* * ESPRESSIF MIT License * * Copyright (c) 2018 <ESPRESSIF SYSTEMS (SHANGHAI) PTE LTD> * * Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case, * it is free of charge, to any person obtaining a copy of this software and associated * documentation files (the "Software"), to deal in the Software without restriction, including * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the Software is furnished * to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all copies or * substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * */ #include "freertos/FreeRTOS.h" #include <string.h> #include <stdlib.h> #include "esp_log.h" #include "jsmn.h" #include "audio_error.h" static const char* TAG = "JSON_UTILS"; static bool jsoneq(const char *json, jsmntok_t *tok, const char *s) { if (tok->type == JSMN_STRING && (int) strlen(s) == tok->end - tok->start && strncmp(json + tok->start, s, tok->end - tok->start) == 0) { return true; } return false; } char *json_get_token_value(const char *json_string, const char *token_name) { jsmn_parser parser; jsmn_init(&parser); jsmntok_t t[20]; int i; int r = jsmn_parse(&parser, json_string, strlen(json_string), t, 20); if (r < 0) { ESP_LOGE(TAG, "Failed to parse JSON: %d", r); return NULL; } /* Assume the top-level element is an object */ if (r < 1 || t[0].type != JSMN_OBJECT) { ESP_LOGE(TAG, "Object expected"); return NULL; } for (i = 1; i < r; i++) { if (jsoneq(json_string, &t[i], token_name) && i < r) { int tok_len = t[i+1].end - t[i+1].start; char *tok = calloc(1, tok_len + 1); AUDIO_MEM_CHECK(TAG, tok, return NULL); memcpy(tok, json_string + t[i+1].start, tok_len); return tok; } } return NULL; }
YifuLiu/AliOS-Things
hardware/chip/espressif_adf/esp-adf/components/adf_utils/json_utils.c
C
apache-2.0
2,547
set(COMPONENT_ADD_INCLUDEDIRS ./include) # Edit following two lines to set component requirements (see docs) set(COMPONENT_REQUIRES ) set(COMPONENT_PRIV_REQUIRES esp_peripherals audio_sal audio_hal esp_dispatcher display_service) if (CONFIG_ESP_LYRAT_V4_2_BOARD) message(STATUS "Current board name is " CONFIG_ESP_LYRAT_V4_2_BOARD) list(APPEND COMPONENT_ADD_INCLUDEDIRS ./lyrat_v4_2) set(COMPONENT_SRCS ./lyrat_v4_2/board.c ./lyrat_v4_2/board_pins_config.c ) endif() if (CONFIG_ESP_LYRAT_V4_3_BOARD) message(STATUS "Current board name is " CONFIG_ESP_LYRAT_V4_3_BOARD) list(APPEND COMPONENT_ADD_INCLUDEDIRS ./lyrat_v4_3) set(COMPONENT_SRCS ./lyrat_v4_3/board.c ./lyrat_v4_3/board_pins_config.c ) endif() if (CONFIG_ESP_LYRAT_MINI_V1_1_BOARD) message(STATUS "Current board name is " CONFIG_ESP_LYRAT_MINI_V1_1_BOARD) list(APPEND COMPONENT_ADD_INCLUDEDIRS ./lyrat_mini_v1_1) set(COMPONENT_SRCS ./lyrat_mini_v1_1/board.c ./lyrat_mini_v1_1/board_pins_config.c ) endif() if (CONFIG_ESP_LYRATD_MSC_V2_1_BOARD) message(STATUS "Current board name is " CONFIG_ESP_LYRATD_MSC_V2_1_BOARD) list(APPEND COMPONENT_ADD_INCLUDEDIRS ./lyratd_msc_v2_1) set(COMPONENT_SRCS ./lyratd_msc_v2_1/board.c ./lyratd_msc_v2_1/board_pins_config.c ) endif() if (CONFIG_ESP_LYRATD_MSC_V2_2_BOARD) message(STATUS "Current board name is " CONFIG_ESP_LYRATD_MSC_V2_2_BOARD) list(APPEND COMPONENT_ADD_INCLUDEDIRS ./lyratd_msc_v2_2) set(COMPONENT_SRCS ./lyratd_msc_v2_2/board.c ./lyratd_msc_v2_2/board_pins_config.c ) endif() if (CONFIG_ESP32_KORVO_DU1906_BOARD) message(STATUS "Current board name is " CONFIG_ESP32_KORVO_DU1906_BOARD) list(APPEND COMPONENT_ADD_INCLUDEDIRS ./esp32_korvo_du1906) set(COMPONENT_SRCS ./esp32_korvo_du1906/board.c ./esp32_korvo_du1906/board_pins_config.c ./esp32_korvo_du1906/du1906_bar_pattern.c ) endif() if (CONFIG_ESP32_S2_KALUGA_1_V1_2_BOARD) message(STATUS "Current board name is " CONFIG_ESP32_S2_KALUGA_1_V1_2_BOARD) list(APPEND COMPONENT_ADD_INCLUDEDIRS ./esp32_s2_kaluga_1_v1_2) set(COMPONENT_SRCS ./esp32_s2_kaluga_1_v1_2/board.c ./esp32_s2_kaluga_1_v1_2/board_pins_config.c ) endif() if (CONFIG_ESP32_S3_KORVO2_V3_BOARD) message(STATUS "Current board name is " CONFIG_ESP32_S3_KORVO2_V3_BOARD) list(APPEND COMPONENT_ADD_INCLUDEDIRS ./esp32_s3_korvo2_v3) set(COMPONENT_SRCS ./esp32_s3_korvo2_v3/board.c ./esp32_s3_korvo2_v3/board_pins_config.c ) endif() if (CONFIG_ESP_M5STACK_CORE2_BOARD) message(STATUS "Current board name is " CONFIG_ESP_M5STACK_CORE2_BOARD) list(APPEND COMPONENT_ADD_INCLUDEDIRS ./m5stack_core2) set(COMPONENT_SRCS ./m5stack_core2/board.c ./m5stack_core2/board_pins_config.c ) endif() register_component()
YifuLiu/AliOS-Things
hardware/chip/espressif_adf/esp-adf/components/audio_board/CMakeLists.txt
CMake
apache-2.0
2,645
# # "main" pseudo-component makefile. # # (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.) COMPONENT_ADD_INCLUDEDIRS := ./include ifdef CONFIG_ESP_LYRAT_V4_3_BOARD COMPONENT_ADD_INCLUDEDIRS += ./lyrat_v4_3 COMPONENT_SRCDIRS += ./lyrat_v4_3 endif ifdef CONFIG_ESP_LYRAT_V4_2_BOARD COMPONENT_ADD_INCLUDEDIRS += ./lyrat_v4_2 COMPONENT_SRCDIRS += ./lyrat_v4_2 endif ifdef CONFIG_ESP_LYRATD_MSC_V2_1_BOARD COMPONENT_ADD_INCLUDEDIRS += ./lyratd_msc_v2_1 COMPONENT_SRCDIRS += ./lyratd_msc_v2_1 COMPONENT_ADD_LDFLAGS += -L$(COMPONENT_PATH)/../audio_hal/driver/zl38063/firmware -lfirmware endif ifdef CONFIG_ESP_LYRATD_MSC_V2_2_BOARD COMPONENT_ADD_INCLUDEDIRS += ./lyratd_msc_v2_2 COMPONENT_SRCDIRS += ./lyratd_msc_v2_2 COMPONENT_ADD_LDFLAGS += -L$(COMPONENT_PATH)/../audio_hal/driver/zl38063/firmware -lfirmware endif ifdef CONFIG_ESP_LYRAT_MINI_V1_1_BOARD COMPONENT_ADD_INCLUDEDIRS += ./lyrat_mini_v1_1 COMPONENT_SRCDIRS += ./lyrat_mini_v1_1 endif ifdef CONFIG_ESP32_KORVO_DU1906_BOARD COMPONENT_ADD_INCLUDEDIRS += ./esp32_korvo_du1906 COMPONENT_SRCDIRS += ./esp32_korvo_du1906 endif ifdef CONFIG_ESP32_S2_KALUGA_1_V1_2_BOARD COMPONENT_ADD_INCLUDEDIRS += ./esp32_s2_kaluga_1_v1_2 COMPONENT_SRCDIRS += ./esp32_s2_kaluga_1_v1_2 endif ifdef CONFIG_ESP32_S3_KORVO2_V3_BOARD COMPONENT_ADD_INCLUDEDIRS += ./esp32_s3_korvo2_v3 COMPONENT_SRCDIRS += ./esp32_s3_korvo2_v3 endif ifdef CONFIG_ESP_M5STACK_CORE2_BOARD COMPONENT_ADD_INCLUDEDIRS += ./m5stack_core2 COMPONENT_SRCDIRS += ./m5stack_core2 endif
YifuLiu/AliOS-Things
hardware/chip/espressif_adf/esp-adf/components/audio_board/component.mk
Makefile
apache-2.0
1,551
/* * ESPRESSIF MIT License * * Copyright (c) 2020 <ESPRESSIF SYSTEMS (SHANGHAI) CO., LTD> * * Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case, * it is free of charge, to any person obtaining a copy of this software and associated * documentation files (the "Software"), to deal in the Software without restriction, including * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the Software is furnished * to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all copies or * substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * */ #include "esp_log.h" #include "board.h" #include "audio_mem.h" #include "periph_sdcard.h" #include "led_indicator.h" #include "periph_adc_button.h" #include "led_bar_ws2812.h" #include "display_service.h" #include "es7243.h" static const char *TAG = "AUDIO_BOARD"; static audio_board_handle_t board_handle; audio_board_handle_t audio_board_init(void) { if (board_handle) { ESP_LOGW(TAG, "The board has already been initialized!"); return board_handle; } board_handle = (audio_board_handle_t) audio_calloc(1, sizeof(struct audio_board_handle)); AUDIO_MEM_CHECK(TAG, board_handle, return NULL); board_handle->audio_hal = audio_board_dac_init(); es7243_adc_set_addr(0x24); board_handle->adc_line_in_hal = audio_board_adc_init(); es7243_adc_set_addr(0x26); board_handle->adc_ref_pa_hal = audio_board_adc_init(); return board_handle; } audio_hal_handle_t audio_board_dac_init(void) { audio_hal_handle_t dac_hal = NULL; audio_hal_codec_config_t audio_codec_cfg = AUDIO_CODEC_DEFAULT_CONFIG(); #ifdef CONFIG_ESP32_KORVO_DU1906_DAC_TAS5805M dac_hal = audio_hal_init(&audio_codec_cfg, &AUDIO_CODEC_TAS5805M_DEFAULT_HANDLE); #elif CONFIG_ESP32_KORVO_DU1906_DAC_ES7148 dac_hal = audio_hal_init(&audio_codec_cfg, &AUDIO_CODEC_ES7148_DEFAULT_HANDLE); i2s_mclk_gpio_select(I2S_NUM_0, GPIO_NUM_0); #endif AUDIO_NULL_CHECK(TAG, dac_hal, return NULL); return dac_hal; } audio_hal_handle_t audio_board_adc_init(void) { audio_hal_handle_t adc_hal = NULL; #ifdef CONFIG_ESP32_KORVO_DU1906_ADC_ES7243 audio_hal_codec_config_t audio_codec_cfg = AUDIO_CODEC_DEFAULT_CONFIG(); adc_hal = audio_hal_init(&audio_codec_cfg, &AUDIO_CODEC_ES7243_DEFAULT_HANDLE); AUDIO_NULL_CHECK(TAG, adc_hal, return NULL); #endif return adc_hal; } display_service_handle_t audio_board_led_init(void) { led_bar_ws2812_handle_t led = led_bar_ws2812_init(get_ws2812_gpio_pin(), get_ws2812_num()); AUDIO_NULL_CHECK(TAG, led, return NULL); display_service_config_t display = { .based_cfg = { .task_stack = 0, .task_prio = 0, .task_core = 0, .task_func = NULL, .service_start = NULL, .service_stop = NULL, .service_destroy = NULL, .service_ioctl = led_bar_ws2812_pattern, .service_name = "DISPLAY_serv", .user_data = NULL, }, .instance = led, }; return display_service_create(&display); } esp_err_t audio_board_key_init(esp_periph_set_handle_t set) { esp_err_t ret = ESP_OK; periph_adc_button_cfg_t adc_btn_cfg = PERIPH_ADC_BUTTON_DEFAULT_CONFIG(); adc_btn_cfg.task_cfg.ext_stack = true; adc_arr_t adc_btn_tag = ADC_DEFAULT_ARR(); adc_btn_tag.adc_ch = ADC1_CHANNEL_0; // GPIO36 adc_btn_tag.total_steps = 4; int btn_array[5] = {200, 900, 1500, 2100, 2930}; adc_btn_tag.adc_level_step = btn_array; adc_btn_cfg.arr = &adc_btn_tag; adc_btn_cfg.arr_size = 1; esp_periph_handle_t adc_btn_handle = periph_adc_button_init(&adc_btn_cfg); AUDIO_NULL_CHECK(TAG, adc_btn_handle, return ESP_ERR_ADF_MEMORY_LACK); ret = esp_periph_start(set, adc_btn_handle); return ret; } esp_err_t audio_board_sdcard_init(esp_periph_set_handle_t set, periph_sdcard_mode_t mode) { if (mode != SD_MODE_1_LINE) { ESP_LOGE(TAG, "current board only support 1-line SD mode!"); return ESP_FAIL; } periph_sdcard_cfg_t sdcard_cfg = { .root = "/sdcard", .card_detect_pin = get_sdcard_intr_gpio(), // GPIO_NUM_34 .mode = mode }; esp_periph_handle_t sdcard_handle = periph_sdcard_init(&sdcard_cfg); esp_err_t ret = esp_periph_start(set, sdcard_handle); int retry_time = 5; bool mount_flag = false; while (retry_time --) { if (periph_sdcard_is_mounted(sdcard_handle)) { mount_flag = true; break; } else { vTaskDelay(500 / portTICK_PERIOD_MS); } } if (mount_flag == false) { ESP_LOGE(TAG, "Sdcard mount failed"); return ESP_FAIL; } return ret; } audio_board_handle_t audio_board_get_handle(void) { return board_handle; } esp_err_t audio_board_deinit(audio_board_handle_t audio_board) { esp_err_t ret = ESP_OK; ret |= audio_hal_deinit(audio_board->audio_hal); audio_free(audio_board); board_handle = NULL; return ret; }
YifuLiu/AliOS-Things
hardware/chip/espressif_adf/esp-adf/components/audio_board/esp32_korvo_du1906/board.c
C
apache-2.0
5,695
/* * ESPRESSIF MIT License * * Copyright (c) 2020 <ESPRESSIF SYSTEMS (SHANGHAI) CO., LTD> * * Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case, * it is free of charge, to any person obtaining a copy of this software and associated * documentation files (the "Software"), to deal in the Software without restriction, including * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the Software is furnished * to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all copies or * substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * */ #ifndef _AUDIO_BOARD_H_ #define _AUDIO_BOARD_H_ #include "audio_hal.h" #include "board_def.h" #include "board_pins_config.h" #include "esp_peripherals.h" #include "display_service.h" #include "periph_sdcard.h" #ifdef __cplusplus extern "C" { #endif extern audio_hal_func_t AUDIO_CODEC_TAS5805M_DEFAULT_HANDLE; extern audio_hal_func_t AUDIO_CODEC_ES7148_DEFAULT_HANDLE; extern audio_hal_func_t AUDIO_CODEC_ES7243_DEFAULT_HANDLE; /** * @brief Audio board handle */ struct audio_board_handle { audio_hal_handle_t audio_hal; /*!< pa hardware abstract layer handle */ audio_hal_handle_t adc_line_in_hal; /*!< adc hardware abstract layer handle */ audio_hal_handle_t adc_ref_pa_hal; /*!< adc hardware abstract layer handle */ }; typedef struct audio_board_handle *audio_board_handle_t; /** * @brief Initialize audio board * * @return The audio board handle */ audio_board_handle_t audio_board_init(void); /** * @brief Initialize DAC chip * * @return The audio hal handle */ audio_hal_handle_t audio_board_dac_init(void); /** * @brief Initialize ADC chip * * @return The audio hal handle */ audio_hal_handle_t audio_board_adc_init(void); /** * @brief Initialize led peripheral and display service * * @return The audio display service handle */ display_service_handle_t audio_board_led_init(void); /** * @brief Initialize key peripheral * * @param set The handle of esp_periph_set_handle_t * * @return * - ESP_OK, success * - Others, fail */ esp_err_t audio_board_key_init(esp_periph_set_handle_t set); /** * @brief Initialize sdcard peripheral * * @param set The handle of esp_periph_set_handle_t * * @return * - ESP_OK, success * - Others, fail */ esp_err_t audio_board_sdcard_init(esp_periph_set_handle_t set, periph_sdcard_mode_t mode); /** * @brief Query audio_board_handle * * @return The audio board handle */ audio_board_handle_t audio_board_get_handle(void); /** * @brief Uninitialize the audio board * * @param audio_board The handle of audio board * * @return ESP_OK, success * others, fail */ esp_err_t audio_board_deinit(audio_board_handle_t audio_board); /** * @brief Get the ws2812 gpio pin * * @return GPIO pin */ int8_t get_ws2812_gpio_pin(void); /** * @brief Get the number of ws2812 * * @return number of ws2812 */ int get_ws2812_num(void); #ifdef __cplusplus } #endif #endif
YifuLiu/AliOS-Things
hardware/chip/espressif_adf/esp-adf/components/audio_board/esp32_korvo_du1906/board.h
C
apache-2.0
3,663
/* * ESPRESSIF MIT License * * Copyright (c) 2020 <ESPRESSIF SYSTEMS (SHANGHAI) CO., LTD> * * Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case, * it is free of charge, to any person obtaining a copy of this software and associated * documentation files (the "Software"), to deal in the Software without restriction, including * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the Software is furnished * to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all copies or * substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * */ #ifndef _AUDIO_BOARD_DEFINITION_H_ #define _AUDIO_BOARD_DEFINITION_H_ #define BUTTON_VOLUP_ID 0 #define BUTTON_VOLDOWN_ID 1 #define BUTTON_MUTE_ID 2 #define BUTTON_SET_ID 3 #define PA_ENABLE_GPIO GPIO_NUM_12 #define ADC_DETECT_GPIO GPIO_NUM_36 #define BATTERY_DETECT_GPIO GPIO_NUM_37 #define SDCARD_OPEN_FILE_NUM_MAX 5 #define SDCARD_INTR_GPIO GPIO_NUM_39 #define ES7243_MCLK_GPIO GPIO_NUM_0 #define WS2812_LED_GPIO_PIN 3 #define WS2812_LED_BAR_NUMBERS 2 #define AUDIO_CODEC_DEFAULT_CONFIG(){ \ .adc_input = AUDIO_HAL_ADC_INPUT_LINE1, \ .dac_output = AUDIO_HAL_DAC_OUTPUT_ALL, \ .codec_mode = AUDIO_HAL_CODEC_MODE_BOTH, \ .i2s_iface = { \ .mode = AUDIO_HAL_MODE_SLAVE, \ .fmt = AUDIO_HAL_I2S_NORMAL, \ .samples = AUDIO_HAL_48K_SAMPLES, \ .bits = AUDIO_HAL_BIT_LENGTH_16BITS, \ }, \ }; #define INPUT_KEY_NUM 4 #define INPUT_KEY_DEFAULT_INFO() { \ { \ .type = PERIPH_ID_ADC_BTN, \ .user_id = INPUT_KEY_USER_ID_VOLUP, \ .act_id = BUTTON_VOLUP_ID, \ }, \ { \ .type = PERIPH_ID_ADC_BTN, \ .user_id = INPUT_KEY_USER_ID_VOLDOWN, \ .act_id = BUTTON_VOLDOWN_ID, \ }, \ { \ .type = PERIPH_ID_ADC_BTN, \ .user_id = INPUT_KEY_USER_ID_MUTE, \ .act_id = BUTTON_MUTE_ID, \ }, \ { \ .type = PERIPH_ID_ADC_BTN, \ .user_id = INPUT_KEY_USER_ID_SET, \ .act_id = BUTTON_SET_ID, \ }, \ } #endif
YifuLiu/AliOS-Things
hardware/chip/espressif_adf/esp-adf/components/audio_board/esp32_korvo_du1906/board_def.h
C
apache-2.0
3,640
/* * ESPRESSIF MIT License * * Copyright (c) 2020 <ESPRESSIF SYSTEMS (SHANGHAI) CO., LTD> * * Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case, * it is free of charge, to any person obtaining a copy of this software and associated * documentation files (the "Software"), to deal in the Software without restriction, including * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the Software is furnished * to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all copies or * substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * */ #include "esp_log.h" #include "string.h" #include "driver/gpio.h" #include "board.h" #include "audio_error.h" #include "audio_mem.h" static const char *TAG = "ESP32_Korvo_DU1906"; esp_err_t get_i2c_pins(i2c_port_t port, i2c_config_t *i2c_config) { AUDIO_NULL_CHECK(TAG, i2c_config, return ESP_FAIL); if (port == I2C_NUM_0 || port == I2C_NUM_1) { i2c_config->sda_io_num = GPIO_NUM_18; i2c_config->scl_io_num = GPIO_NUM_23; } else { i2c_config->sda_io_num = -1; i2c_config->scl_io_num = -1; ESP_LOGE(TAG, "i2c port %d is not supported", port); return ESP_FAIL; } return ESP_OK; } esp_err_t get_i2s_pins(i2s_port_t port, i2s_pin_config_t *i2s_config) { AUDIO_NULL_CHECK(TAG, i2s_config, return ESP_FAIL); if (port == I2S_NUM_0) { i2s_config->bck_io_num = GPIO_NUM_4; i2s_config->ws_io_num = GPIO_NUM_13; i2s_config->data_out_num = GPIO_NUM_16; i2s_config->data_in_num = GPIO_NUM_39; } else if (port == I2S_NUM_1) { i2s_config->bck_io_num = -1; i2s_config->ws_io_num = -1; i2s_config->data_out_num = -1; i2s_config->data_in_num = -1; } else { memset(i2s_config, -1, sizeof(i2s_pin_config_t)); ESP_LOGE(TAG, "i2s port %d is not supported", port); return ESP_FAIL; } return ESP_OK; } esp_err_t get_spi_pins(spi_bus_config_t *spi_config, spi_device_interface_config_t *spi_device_interface_config) { AUDIO_NULL_CHECK(TAG, spi_config, return ESP_FAIL); AUDIO_NULL_CHECK(TAG, spi_device_interface_config, return ESP_FAIL); spi_config->mosi_io_num = -1; spi_config->miso_io_num = -1; spi_config->sclk_io_num = -1; spi_config->quadwp_io_num = -1; spi_config->quadhd_io_num = -1; spi_device_interface_config->spics_io_num = -1; ESP_LOGW(TAG, "SPI interface is not supported"); return ESP_OK; } esp_err_t i2s_mclk_gpio_select(i2s_port_t i2s_num, gpio_num_t gpio_num) { if (i2s_num >= I2S_NUM_MAX) { ESP_LOGE(TAG, "Does not support i2s number(%d)", i2s_num); return ESP_ERR_INVALID_ARG; } if (gpio_num != GPIO_NUM_0 && gpio_num != GPIO_NUM_1 && gpio_num != GPIO_NUM_3) { ESP_LOGE(TAG, "Only support GPIO0/GPIO1/GPIO3, gpio_num:%d", gpio_num); return ESP_ERR_INVALID_ARG; } ESP_LOGI(TAG, "I2S%d, MCLK output by GPIO%d", i2s_num, gpio_num); if (i2s_num == I2S_NUM_0) { if (gpio_num == GPIO_NUM_0) { PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO0_U, FUNC_GPIO0_CLK_OUT1); WRITE_PERI_REG(PIN_CTRL, 0xFFF0); } else if (gpio_num == GPIO_NUM_1) { PIN_FUNC_SELECT(PERIPHS_IO_MUX_U0TXD_U, FUNC_U0TXD_CLK_OUT3); WRITE_PERI_REG(PIN_CTRL, 0xF0F0); } else { PIN_FUNC_SELECT(PERIPHS_IO_MUX_U0RXD_U, FUNC_U0RXD_CLK_OUT2); WRITE_PERI_REG(PIN_CTRL, 0xFF00); } } else if (i2s_num == I2S_NUM_1) { if (gpio_num == GPIO_NUM_0) { PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO0_U, FUNC_GPIO0_CLK_OUT1); WRITE_PERI_REG(PIN_CTRL, 0xFFFF); } else if (gpio_num == GPIO_NUM_1) { PIN_FUNC_SELECT(PERIPHS_IO_MUX_U0TXD_U, FUNC_U0TXD_CLK_OUT3); WRITE_PERI_REG(PIN_CTRL, 0xF0FF); } else { PIN_FUNC_SELECT(PERIPHS_IO_MUX_U0RXD_U, FUNC_U0RXD_CLK_OUT2); WRITE_PERI_REG(PIN_CTRL, 0xFF0F); } } return ESP_OK; } // sdcard int8_t get_sdcard_intr_gpio(void) { return SDCARD_INTR_GPIO; } int8_t get_sdcard_open_file_num_max(void) { return SDCARD_OPEN_FILE_NUM_MAX; } // Using "mute" button instead of "play" button as the audio control button, // since `ESP32-Korvo-DU1906` board has not "play" button int8_t get_input_play_id(void) { return BUTTON_MUTE_ID; } int8_t get_input_set_id(void) { return BUTTON_SET_ID; } int8_t get_input_volup_id(void) { return BUTTON_VOLUP_ID; } int8_t get_input_voldown_id(void) { return BUTTON_VOLDOWN_ID; } int8_t get_pa_enable_gpio(void) { return PA_ENABLE_GPIO; } int8_t get_es7243_mclk_gpio(void) { return ES7243_MCLK_GPIO; }
YifuLiu/AliOS-Things
hardware/chip/espressif_adf/esp-adf/components/audio_board/esp32_korvo_du1906/board_pins_config.c
C
apache-2.0
5,369
/* * ESPRESSIF MIT License * * Copyright (c) 2020 <ESPRESSIF SYSTEMS (SHANGHAI) CO., LTD> * * Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case, * it is free of charge, to any person obtaining a copy of this software and associated * documentation files (the "Software"), to deal in the Software without restriction, including * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the Software is furnished * to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all copies or * substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * */ #include "display_service.h" #include "periph_ws2812.h" #include "board_def.h" #include "string.h" #include "esp_log.h" const struct periph_ws2812_ctrl_cfg ws2812_display_pattern[DISPLAY_PATTERN_MAX][WS2812_LED_BAR_NUMBERS] = { { { .mode = PERIPH_WS2812_BLINK, .color = LED2812_COLOR_RED, .loop = 1000, .time_off_ms = 200, .time_on_ms = 400, }, { .mode = PERIPH_WS2812_BLINK, .color = LED2812_COLOR_RED, .loop = 1000, .time_off_ms = 200, .time_on_ms = 400, } // 0 }, { { .mode = PERIPH_WS2812_FADE, .color = LED2812_COLOR_PURPLE, .loop = 0xFFFFFFFF, .time_off_ms = 1500, .time_on_ms = 1500, }, { .mode = PERIPH_WS2812_FADE, .color = LED2812_COLOR_PURPLE, .loop = 0xFFFFFFFF, .time_off_ms = 1500, .time_on_ms = 1500, } // 1 }, { { .mode = PERIPH_WS2812_BLINK, .color = LED2812_COLOR_WHITE, .loop = 0xFFFFFFFF, .time_off_ms = 200, .time_on_ms = 800, }, { .mode = PERIPH_WS2812_BLINK, .color = LED2812_COLOR_WHITE, .loop = 0xFFFFFFFF, .time_off_ms = 200, .time_on_ms = 800, } // 2 }, { { .mode = PERIPH_WS2812_ONE, .color = LED2812_COLOR_BLACK , .loop = 0, .time_off_ms = 0, .time_on_ms = 0, }, { .mode = PERIPH_WS2812_ONE, .color = LED2812_COLOR_BLACK, .loop = 0, .time_off_ms = 0, .time_on_ms = 0, } // 3 }, { { .mode = PERIPH_WS2812_ONE, .color = LED2812_COLOR_RED, .loop = 1, .time_off_ms = 1000, .time_on_ms = 4000, }, { .mode = PERIPH_WS2812_ONE, .color = LED2812_COLOR_RED, .loop = 1, .time_off_ms = 1000, .time_on_ms = 4000, } // 4 }, { { .mode = PERIPH_WS2812_BLINK, .color = LED2812_COLOR_WHITE, .loop = 5, .time_off_ms = 200, .time_on_ms = 1000, }, { .mode = PERIPH_WS2812_BLINK, .color = LED2812_COLOR_WHITE, .loop = 5, .time_off_ms = 200, .time_on_ms = 1000, } // 5 }, { { .mode = PERIPH_WS2812_BLINK, .color = LED2812_COLOR_BLUE, .loop = 100, .time_off_ms = 200, .time_on_ms = 800, }, { .mode = PERIPH_WS2812_BLINK, .color = LED2812_COLOR_BLUE, .loop = 100, .time_off_ms = 200, .time_on_ms = 800, } // 6 }, { { .mode = PERIPH_WS2812_BLINK, .color = LED2812_COLOR_PURPLE, .loop = 4, .time_off_ms = 100, .time_on_ms = 100, }, { .mode = PERIPH_WS2812_BLINK, .color = LED2812_COLOR_PURPLE, .loop = 4, .time_off_ms = 100, .time_on_ms = 100, } // 7 }, { { .mode = PERIPH_WS2812_BLINK, .color = LED2812_COLOR_PURPLE, .loop = 4, .time_off_ms = 100, .time_on_ms = 100, }, { .mode = PERIPH_WS2812_BLINK, .color = LED2812_COLOR_PURPLE, .loop = 4, .time_off_ms = 100, .time_on_ms = 100, } // 8 }, { { .mode = PERIPH_WS2812_ONE, .color = LED2812_COLOR_PURPLE, .loop = 0, .time_off_ms = 0, .time_on_ms = 0, }, { .mode = PERIPH_WS2812_ONE, .color = LED2812_COLOR_PURPLE, .loop = 0, .time_off_ms = 0, .time_on_ms = 0, } // 9 }, { { .mode = PERIPH_WS2812_BLINK, .color = LED2812_COLOR_PURPLE, .loop = 2, .time_off_ms = 200, .time_on_ms = 400, }, { .mode = PERIPH_WS2812_BLINK, .color = LED2812_COLOR_PURPLE, .loop = 2, .time_off_ms = 200, .time_on_ms = 400, } // 10 }, { { .mode = PERIPH_WS2812_FADE, .color = LED2812_COLOR_PURPLE, .loop = 100, .time_off_ms = 2000, .time_on_ms = 2000, }, { .mode = PERIPH_WS2812_FADE, .color = LED2812_COLOR_PURPLE, .loop = 100, .time_off_ms = 2000, .time_on_ms = 2000, } // 11 }, { { .mode = PERIPH_WS2812_BLINK, .color = LED2812_COLOR_PURPLE, .loop = 2, .time_off_ms = 200, .time_on_ms = 400, }, { .mode = PERIPH_WS2812_BLINK, .color = LED2812_COLOR_PURPLE, .loop = 2, .time_off_ms = 200, .time_on_ms = 400, } // 12 }, { { .mode = PERIPH_WS2812_ONE, .color = LED2812_COLOR_BLUE, .loop = 0, .time_off_ms = 0, .time_on_ms = 0, }, { .mode = PERIPH_WS2812_ONE, .color = LED2812_COLOR_BLUE, .loop = 0, .time_off_ms = 0, .time_on_ms = 0, } // 13 }, { { .mode = PERIPH_WS2812_ONE, .color = LED2812_COLOR_BLACK, .loop = 0, .time_off_ms = 0, .time_on_ms = 0, }, { .mode = PERIPH_WS2812_ONE, .color = LED2812_COLOR_BLACK, .loop = 0, .time_off_ms = 0, .time_on_ms = 0, } // 14 }, { { .mode = PERIPH_WS2812_BLINK, .color = LED2812_COLOR_YELLOW, .loop = 2000, .time_off_ms = 200, .time_on_ms = 600, }, { .mode = PERIPH_WS2812_BLINK, .color = LED2812_COLOR_YELLOW, .loop = 2000, .time_off_ms = 200, .time_on_ms = 600, } // 15 }, { { .mode = PERIPH_WS2812_ONE, .color = LED2812_COLOR_BLACK, .loop = 0, .time_off_ms = 0, .time_on_ms = 0, }, { .mode = PERIPH_WS2812_ONE, .color = LED2812_COLOR_BLACK, .loop = 0, .time_off_ms = 0, .time_on_ms = 0, } // 16 }, { { .mode = PERIPH_WS2812_FADE, .color = LED2812_COLOR_GREEN, .loop = 1, .time_off_ms = 0, .time_on_ms = 1000, }, { .mode = PERIPH_WS2812_FADE, .color = LED2812_COLOR_GREEN, .loop = 1, .time_off_ms = 0, .time_on_ms = 1000, } // 17 }, { { .mode = PERIPH_WS2812_ONE, .color = LED2812_COLOR_ORANGE, .loop = 0, .time_off_ms = 0, .time_on_ms = 0, }, { .mode = PERIPH_WS2812_ONE, .color = LED2812_COLOR_ORANGE, .loop = 0, .time_off_ms = 0, .time_on_ms = 0, } // 18 }, { { .mode = PERIPH_WS2812_ONE, .color = LED2812_COLOR_BLACK, .loop = 0, .time_off_ms = 0, .time_on_ms = 0, }, { .mode = PERIPH_WS2812_ONE, .color = LED2812_COLOR_BLACK, .loop = 0, .time_off_ms = 0, .time_on_ms = 0, } // 19 }, { { .mode = PERIPH_WS2812_ONE, .color = LED2812_COLOR_WHITE, .loop = 0, .time_off_ms = 0, .time_on_ms = 0, }, { .mode = PERIPH_WS2812_ONE, .color = LED2812_COLOR_WHITE, .loop = 0, .time_off_ms = 0, .time_on_ms = 0, } // 20 }, { { .mode = PERIPH_WS2812_ONE, .color = LED2812_COLOR_BLACK, .loop = 0, .time_off_ms = 0, .time_on_ms = 0, }, { .mode = PERIPH_WS2812_ONE, .color = LED2812_COLOR_BLACK, .loop = 0, .time_off_ms = 0, .time_on_ms = 0, } // 21 }, { { .mode = PERIPH_WS2812_BLINK, .color = LED2812_COLOR_RED, .loop = 1000, .time_off_ms = 200, .time_on_ms = 800, }, { .mode = PERIPH_WS2812_BLINK, .color = LED2812_COLOR_RED, .loop = 1000, .time_off_ms = 200, .time_on_ms = 800, } // 22 }, { { .mode = PERIPH_WS2812_FADE, .color = LED2812_COLOR_PURPLE, .loop = 1000, .time_off_ms = 1500, .time_on_ms = 1500, }, { .mode = PERIPH_WS2812_FADE, .color = LED2812_COLOR_PURPLE, .loop = 1000, .time_off_ms = 1500, .time_on_ms = 1500, } // 23 }, { { .mode = PERIPH_WS2812_BLINK, .color = LED2812_COLOR_PURPLE, .loop = 1000, .time_off_ms = 1000, .time_on_ms = 2000, }, { .mode = PERIPH_WS2812_BLINK, .color = LED2812_COLOR_PURPLE, .loop = 1000, .time_off_ms = 1000, .time_on_ms = 2000, } // 24 }, { { .mode = PERIPH_WS2812_ONE, .color = LED2812_COLOR_PURPLE, .loop = 0, .time_off_ms = 0, .time_on_ms = 0, }, { .mode = PERIPH_WS2812_ONE, .color = LED2812_COLOR_PURPLE, .loop = 0, .time_off_ms = 0, .time_on_ms = 0, } // 25 } , { { .mode = PERIPH_WS2812_BLINK, .color = LED2812_COLOR_RED, .loop = 0xFFFFFFFF, .time_off_ms = 2000, .time_on_ms = 2000, }, { .mode = PERIPH_WS2812_BLINK, .color = LED2812_COLOR_RED, .loop = 0xFFFFFFFF, .time_off_ms = 2000, .time_on_ms = 2000, } // 26 }, { { .mode = PERIPH_WS2812_BLINK, .color = LED2812_COLOR_BLUE, .loop = 0xFFFFFFFF, .time_off_ms = 500, .time_on_ms = 500, }, { .mode = PERIPH_WS2812_BLINK, .color = LED2812_COLOR_BLUE, .loop = 0xFFFFFFFF, .time_off_ms = 500, .time_on_ms = 500, } // 27, }, { { .mode = PERIPH_WS2812_ONE, .color = LED2812_COLOR_BLACK, .loop = 0, .time_off_ms = 0, .time_on_ms = 0, }, { .mode = PERIPH_WS2812_ONE, .color = LED2812_COLOR_BLACK, .loop = 0, .time_off_ms = 0, .time_on_ms = 0, } // 28, } }; int8_t get_ws2812_gpio_pin(void) { return WS2812_LED_GPIO_PIN; } int get_ws2812_num(void) { return WS2812_LED_BAR_NUMBERS; } void ws2812_pattern_copy(struct periph_ws2812_ctrl_cfg *p) { ESP_LOGD("ws2812_pattern_copy", "has been called, %s %d", __FILE__, __LINE__); memcpy(p, ws2812_display_pattern, sizeof(ws2812_display_pattern)); }
YifuLiu/AliOS-Things
hardware/chip/espressif_adf/esp-adf/components/audio_board/esp32_korvo_du1906/du1906_bar_pattern.c
C
apache-2.0
13,354
/* * ESPRESSIF MIT License * * Copyright (c) 2020 <ESPRESSIF SYSTEMS (SHANGHAI) CO., LTD> * * Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case, * it is free of charge, to any person obtaining a copy of this software and associated * documentation files (the "Software"), to deal in the Software without restriction, including * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the Software is furnished * to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all copies or * substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * */ #include "esp_log.h" #include "board.h" #include "audio_mem.h" #include "periph_adc_button.h" static const char *TAG = "AUDIO_BOARD"; static audio_board_handle_t board_handle = NULL; audio_board_handle_t audio_board_init(void) { if (board_handle) { ESP_LOGW(TAG, "The board has already been initialized!"); return board_handle; } board_handle = (audio_board_handle_t) audio_calloc(1, sizeof(struct audio_board_handle)); AUDIO_MEM_CHECK(TAG, board_handle, return NULL); board_handle->audio_hal = audio_board_codec_init(); return board_handle; } audio_hal_handle_t audio_board_codec_init(void) { audio_hal_codec_config_t audio_codec_cfg = AUDIO_CODEC_DEFAULT_CONFIG(); audio_hal_handle_t codec_hal = audio_hal_init(&audio_codec_cfg, &AUDIO_CODEC_ES8311_DEFAULT_HANDLE); AUDIO_NULL_CHECK(TAG, codec_hal, return NULL); return codec_hal; } esp_err_t audio_board_sdcard_init(esp_periph_set_handle_t set, periph_sdcard_mode_t mode) { esp_err_t ret = ESP_OK; return ret; } display_service_handle_t audio_board_led_init(void) { // TODO return NULL; } esp_err_t audio_board_key_init(esp_periph_set_handle_t set) { esp_err_t ret = ESP_OK; periph_adc_button_cfg_t adc_btn_cfg = PERIPH_ADC_BUTTON_DEFAULT_CONFIG(); adc_arr_t adc_btn_tag = ADC_DEFAULT_ARR(); adc_btn_tag.adc_ch = ADC1_CHANNEL_5; adc_btn_tag.total_steps = 6; int btn_array[7] = {190, 600, 1000, 1375, 1775, 2195, 2610}; adc_btn_tag.adc_level_step = btn_array; adc_btn_cfg.arr = &adc_btn_tag; adc_btn_cfg.arr_size = 1; esp_periph_handle_t adc_btn_handle = periph_adc_button_init(&adc_btn_cfg); AUDIO_NULL_CHECK(TAG, adc_btn_handle, return ESP_ERR_ADF_MEMORY_LACK); ret = esp_periph_start(set, adc_btn_handle); return ret; } audio_board_handle_t audio_board_get_handle(void) { return board_handle; } esp_err_t audio_board_deinit(audio_board_handle_t audio_board) { esp_err_t ret = ESP_OK; ret = audio_hal_deinit(audio_board->audio_hal); audio_board->audio_hal = NULL; audio_free(audio_board); board_handle = NULL; return ret; }
YifuLiu/AliOS-Things
hardware/chip/espressif_adf/esp-adf/components/audio_board/esp32_s2_kaluga_1_v1_2/board.c
C
apache-2.0
3,375
/* * ESPRESSIF MIT License * * Copyright (c) 2020 <ESPRESSIF SYSTEMS (SHANGHAI) CO., LTD> * * Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case, * it is free of charge, to any person obtaining a copy of this software and associated * documentation files (the "Software"), to deal in the Software without restriction, including * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the Software is furnished * to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all copies or * substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * */ #ifndef _AUDIO_BOARD_H_ #define _AUDIO_BOARD_H_ #include "audio_hal.h" #include "board_def.h" #include "board_pins_config.h" #include "esp_peripherals.h" #include "display_service.h" #include "periph_sdcard.h" #ifdef __cplusplus extern "C" { #endif /** * @brief Audio board handle */ struct audio_board_handle { audio_hal_handle_t audio_hal; /*!< audio hardware abstract layer handle */ }; typedef struct audio_board_handle *audio_board_handle_t; /** * @brief Initialize audio board * * @return The audio board handle */ audio_board_handle_t audio_board_init(void); /** * @brief Initialize codec chip * * @return The audio hal handle */ audio_hal_handle_t audio_board_codec_init(void); /** * @brief Initialize led peripheral and display service * * @return The audio display service handle */ display_service_handle_t audio_board_led_init(void); /** * @brief Initialize sdcard peripheral * * @param set The handle of esp_periph_set_handle_t * * @return * - ESP_OK, success * - Others, fail */ esp_err_t audio_board_sdcard_init(esp_periph_set_handle_t set, periph_sdcard_mode_t mode); /** * @brief Initialize key peripheral * * @param set The handle of esp_periph_set_handle_t * * @return * - ESP_OK, success * - Others, fail */ esp_err_t audio_board_key_init(esp_periph_set_handle_t set); /** * @brief Query audio_board_handle * * @return The audio board handle */ audio_board_handle_t audio_board_get_handle(void); /** * @brief Uninitialize the audio board * * @param audio_board The handle of audio board * * @return ESP_OK success, * others fail */ esp_err_t audio_board_deinit(audio_board_handle_t audio_board); #ifdef __cplusplus } #endif #endif
YifuLiu/AliOS-Things
hardware/chip/espressif_adf/esp-adf/components/audio_board/esp32_s2_kaluga_1_v1_2/board.h
C
apache-2.0
2,973
/* * ESPRESSIF MIT License * * Copyright (c) 2020 <ESPRESSIF SYSTEMS (SHANGHAI) CO., LTD> * * Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case, * it is free of charge, to any person obtaining a copy of this software and associated * documentation files (the "Software"), to deal in the Software without restriction, including * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the Software is furnished * to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all copies or * substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * */ #ifndef _AUDIO_BOARD_DEFINITION_H_ #define _AUDIO_BOARD_DEFINITION_H_ #include "driver/touch_pad.h" #define BUTTON_VOLUP_ID 0 #define BUTTON_VOLDOWN_ID 1 #define BUTTON_SET_ID 2 #define BUTTON_PLAY_ID 3 #define BUTTON_MODE_ID 4 #define BUTTON_REC_ID 5 #define PA_ENABLE_GPIO 10 #define BUTTON_ADC 6 #define WS2812_LED_GPIO 45 #define ES8311_MCLK_SOURCE 1 /* 0 From MCLK, 1 From BCLK */ extern audio_hal_func_t AUDIO_CODEC_ES8311_DEFAULT_HANDLE; #define AUDIO_CODEC_DEFAULT_CONFIG(){ \ .adc_input = AUDIO_HAL_ADC_INPUT_LINE1, \ .dac_output = AUDIO_HAL_DAC_OUTPUT_ALL, \ .codec_mode = AUDIO_HAL_CODEC_MODE_BOTH, \ .i2s_iface = { \ .mode = AUDIO_HAL_MODE_SLAVE, \ .fmt = AUDIO_HAL_I2S_NORMAL, \ .samples = AUDIO_HAL_48K_SAMPLES, \ .bits = AUDIO_HAL_BIT_LENGTH_16BITS, \ }, \ }; #define INPUT_KEY_NUM 6 #define INPUT_KEY_DEFAULT_INFO() { \ { \ .type = PERIPH_ID_ADC_BTN, \ .user_id = INPUT_KEY_USER_ID_REC, \ .act_id = BUTTON_REC_ID, \ }, \ { \ .type = PERIPH_ID_ADC_BTN, \ .user_id = INPUT_KEY_USER_ID_MODE, \ .act_id = BUTTON_MODE_ID, \ }, \ { \ .type = PERIPH_ID_ADC_BTN, \ .user_id = INPUT_KEY_USER_ID_SET, \ .act_id = BUTTON_SET_ID, \ }, \ { \ .type = PERIPH_ID_ADC_BTN, \ .user_id = INPUT_KEY_USER_ID_PLAY, \ .act_id = BUTTON_PLAY_ID, \ }, \ { \ .type = PERIPH_ID_ADC_BTN, \ .user_id = INPUT_KEY_USER_ID_VOLUP, \ .act_id = BUTTON_VOLUP_ID, \ }, \ { \ .type = PERIPH_ID_ADC_BTN, \ .user_id = INPUT_KEY_USER_ID_VOLDOWN, \ .act_id = BUTTON_VOLDOWN_ID, \ } \ } #endif
YifuLiu/AliOS-Things
hardware/chip/espressif_adf/esp-adf/components/audio_board/esp32_s2_kaluga_1_v1_2/board_def.h
C
apache-2.0
4,217
/* * ESPRESSIF MIT License * * Copyright (c) 2020 <ESPRESSIF SYSTEMS (SHANGHAI) CO., LTD> * * Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case, * it is free of charge, to any person obtaining a copy of this software and associated * documentation files (the "Software"), to deal in the Software without restriction, including * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the Software is furnished * to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all copies or * substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * */ #include "esp_log.h" #include "driver/gpio.h" #include <string.h> #include "board.h" #include "audio_error.h" #include "audio_mem.h" static const char *TAG = "KALUGA_V1_2"; esp_err_t get_i2c_pins(i2c_port_t port, i2c_config_t *i2c_config) { AUDIO_NULL_CHECK(TAG, i2c_config, return ESP_FAIL); if (port == I2C_NUM_0) { i2c_config->sda_io_num = GPIO_NUM_8; i2c_config->scl_io_num = GPIO_NUM_7; } else { i2c_config->sda_io_num = -1; i2c_config->scl_io_num = -1; ESP_LOGE(TAG, "i2c port %d is not supported", port); return ESP_FAIL; } return ESP_OK; } esp_err_t get_i2s_pins(i2s_port_t port, i2s_pin_config_t *i2s_config) { AUDIO_NULL_CHECK(TAG, i2s_config, return ESP_FAIL); i2s_config->bck_io_num = GPIO_NUM_18; i2s_config->ws_io_num = GPIO_NUM_17; i2s_config->data_out_num = GPIO_NUM_12; i2s_config->data_in_num = GPIO_NUM_46; return ESP_OK; } esp_err_t get_spi_pins(spi_bus_config_t *spi_config, spi_device_interface_config_t *spi_device_interface_config) { AUDIO_NULL_CHECK(TAG, spi_config, return ESP_FAIL); AUDIO_NULL_CHECK(TAG, spi_device_interface_config, return ESP_FAIL); spi_config->mosi_io_num = -1; spi_config->miso_io_num = -1; spi_config->sclk_io_num = -1; spi_config->quadwp_io_num = -1; spi_config->quadhd_io_num = -1; spi_device_interface_config->spics_io_num = -1; ESP_LOGW(TAG, "SPI interface is not supported"); return ESP_OK; } esp_err_t i2s_mclk_gpio_select(i2s_port_t i2s_num, gpio_num_t gpio_num) { if (i2s_num >= I2S_NUM_MAX) { ESP_LOGE(TAG, "Does not support i2s number(%d)", i2s_num); return ESP_ERR_INVALID_ARG; } gpio_num = (gpio_num_t)GPIO_NUM_35; ESP_LOGD(TAG, "I2S%d, MCLK output by GPIO%d", i2s_num, gpio_num); gpio_matrix_out(gpio_num, CLK_I2S_MUX_IDX, 0, 0); return ESP_OK; } // input-output pins int8_t get_pa_enable_gpio(void) { return PA_ENABLE_GPIO; } // adc button id int8_t get_input_rec_id(void) { return BUTTON_REC_ID; } int8_t get_input_mode_id(void) { return BUTTON_MODE_ID; } int8_t get_input_set_id(void) { return BUTTON_SET_ID; } int8_t get_input_play_id(void) { return BUTTON_PLAY_ID; } int8_t get_input_volup_id(void) { return BUTTON_VOLUP_ID; } int8_t get_input_voldown_id(void) { return BUTTON_VOLDOWN_ID; } // led pins int8_t get_ws2812_led_gpio(void) { return WS2812_LED_GPIO; } int8_t get_es8311_mclk_src(void) { return ES8311_MCLK_SOURCE; }
YifuLiu/AliOS-Things
hardware/chip/espressif_adf/esp-adf/components/audio_board/esp32_s2_kaluga_1_v1_2/board_pins_config.c
C
apache-2.0
3,758
/* * ESPRESSIF MIT License * * Copyright (c) 2021 <ESPRESSIF SYSTEMS (SHANGHAI) CO., LTD> * * Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case, * it is free of charge, to any person obtaining a copy of this software and associated * documentation files (the "Software"), to deal in the Software without restriction, including * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the Software is furnished * to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all copies or * substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * */ #include "esp_log.h" #include "board.h" #include "audio_mem.h" #include "periph_sdcard.h" #include "led_indicator.h" #include "periph_adc_button.h" #include "tca9554.h" static const char *TAG = "AUDIO_BOARD"; static audio_board_handle_t board_handle = 0; audio_board_handle_t audio_board_init(void) { if (board_handle) { ESP_LOGW(TAG, "The board has already been initialized!"); return board_handle; } board_handle = (audio_board_handle_t) audio_calloc(1, sizeof(struct audio_board_handle)); AUDIO_MEM_CHECK(TAG, board_handle, return NULL); board_handle->audio_hal = audio_board_codec_init(); board_handle->adc_hal = audio_board_adc_init(); return board_handle; } audio_hal_handle_t audio_board_adc_init(void) { audio_hal_codec_config_t audio_codec_cfg = AUDIO_CODEC_DEFAULT_CONFIG(); audio_hal_handle_t adc_hal = NULL; adc_hal = audio_hal_init(&audio_codec_cfg, &AUDIO_CODEC_ES7210_DEFAULT_HANDLE); AUDIO_NULL_CHECK(TAG, adc_hal, return NULL); return adc_hal; } audio_hal_handle_t audio_board_codec_init(void) { audio_hal_codec_config_t audio_codec_cfg = AUDIO_CODEC_DEFAULT_CONFIG(); audio_hal_handle_t codec_hal = audio_hal_init(&audio_codec_cfg, &AUDIO_CODEC_ES8311_DEFAULT_HANDLE); AUDIO_NULL_CHECK(TAG, codec_hal, return NULL); return codec_hal; } display_service_handle_t audio_board_led_init(void) { // TBD return NULL; } esp_err_t audio_board_key_init(esp_periph_set_handle_t set) { esp_err_t ret = ESP_OK; periph_adc_button_cfg_t adc_btn_cfg = PERIPH_ADC_BUTTON_DEFAULT_CONFIG(); adc_arr_t adc_btn_tag = ADC_DEFAULT_ARR(); adc_btn_tag.total_steps = 6; adc_btn_tag.adc_ch = ADC1_CHANNEL_4; int btn_array[7] = {190, 600, 1000, 1375, 1775, 2195, 3000}; adc_btn_tag.adc_level_step = btn_array; adc_btn_cfg.arr = &adc_btn_tag; adc_btn_cfg.arr_size = 1; esp_periph_handle_t adc_btn_handle = periph_adc_button_init(&adc_btn_cfg); AUDIO_NULL_CHECK(TAG, adc_btn_handle, return ESP_ERR_ADF_MEMORY_LACK); ret = esp_periph_start(set, adc_btn_handle); return ret; } esp_err_t audio_board_sdcard_init(esp_periph_set_handle_t set, periph_sdcard_mode_t mode) { if (mode != SD_MODE_1_LINE) { ESP_LOGE(TAG, "current board only support 1-line SD mode!"); return ESP_FAIL; } periph_sdcard_cfg_t sdcard_cfg = { .root = "/sdcard", .card_detect_pin = get_sdcard_intr_gpio(), .mode = mode }; esp_periph_handle_t sdcard_handle = periph_sdcard_init(&sdcard_cfg); esp_err_t ret = esp_periph_start(set, sdcard_handle); int retry_time = 5; bool mount_flag = false; while (retry_time --) { if (periph_sdcard_is_mounted(sdcard_handle)) { mount_flag = true; break; } else { vTaskDelay(500 / portTICK_PERIOD_MS); } } if (mount_flag == false) { ESP_LOGE(TAG, "Sdcard mount failed"); return ESP_FAIL; } return ret; } audio_board_handle_t audio_board_get_handle(void) { return board_handle; } esp_err_t audio_board_deinit(audio_board_handle_t audio_board) { esp_err_t ret = ESP_OK; ret |= audio_hal_deinit(audio_board->audio_hal); ret |= audio_hal_deinit(audio_board->adc_hal); audio_free(audio_board); board_handle = NULL; return ret; }
YifuLiu/AliOS-Things
hardware/chip/espressif_adf/esp-adf/components/audio_board/esp32_s3_korvo2_v3/board.c
C
apache-2.0
4,595
/* * ESPRESSIF MIT License * * Copyright (c) 2021 <ESPRESSIF SYSTEMS (SHANGHAI) CO., LTD> * * Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case, * it is free of charge, to any person obtaining a copy of this software and associated * documentation files (the "Software"), to deal in the Software without restriction, including * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the Software is furnished * to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all copies or * substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * */ #ifndef _AUDIO_BOARD_H_ #define _AUDIO_BOARD_H_ #include "audio_hal.h" #include "board_def.h" #include "board_pins_config.h" #include "esp_peripherals.h" #include "display_service.h" #include "periph_sdcard.h" #ifdef __cplusplus extern "C" { #endif /** * @brief Audio board handle */ struct audio_board_handle { audio_hal_handle_t audio_hal; /*!< audio hardware abstract layer handle */ audio_hal_handle_t adc_hal; /*!< adc hardware abstract layer handle */ }; typedef struct audio_board_handle *audio_board_handle_t; /** * @brief Initialize audio board * * @return The audio board handle */ audio_board_handle_t audio_board_init(void); /** * @brief Initialize codec chip * * @return The audio hal handle */ audio_hal_handle_t audio_board_codec_init(void); /** * @brief Initialize adc * * @return The adc hal handle */ audio_hal_handle_t audio_board_adc_init(void); /** * @brief Initialize led peripheral and display service * * @return The audio display service handle */ display_service_handle_t audio_board_led_init(void); /** * @brief Initialize led peripheral and display service * * @return The audio display service handle */ display_service_handle_t audio_board_blue_led_init(void); /** * @brief Initialize key peripheral * * @param set The handle of esp_periph_set_handle_t * * @return * - ESP_OK, success * - Others, fail */ esp_err_t audio_board_key_init(esp_periph_set_handle_t set); /** * @brief Initialize sdcard peripheral * * @param set The handle of esp_periph_set_handle_t * * @return * - ESP_OK, success * - Others, fail */ esp_err_t audio_board_sdcard_init(esp_periph_set_handle_t set, periph_sdcard_mode_t mode); /** * @brief Query audio_board_handle * * @return The audio board handle */ audio_board_handle_t audio_board_get_handle(void); /** * @brief Uninitialize the audio board * * @param audio_board The handle of audio board * * @return 0 success, * others fail */ esp_err_t audio_board_deinit(audio_board_handle_t audio_board); #ifdef __cplusplus } #endif #endif
YifuLiu/AliOS-Things
hardware/chip/espressif_adf/esp-adf/components/audio_board/esp32_s3_korvo2_v3/board.h
C
apache-2.0
3,334
/* * ESPRESSIF MIT License * * Copyright (c) 2021 <ESPRESSIF SYSTEMS (SHANGHAI) CO., LTD> * * Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case, * it is free of charge, to any person obtaining a copy of this software and associated * documentation files (the "Software"), to deal in the Software without restriction, including * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the Software is furnished * to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all copies or * substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * */ #ifndef _AUDIO_BOARD_DEFINITION_H_ #define _AUDIO_BOARD_DEFINITION_H_ #define SDCARD_OPEN_FILE_NUM_MAX 5 #define SDCARD_INTR_GPIO -1 #define SDCARD_PWR_CTRL -1 // Based on ADC array voltage ID #define BUTTON_VOLUP_ID 0 #define BUTTON_VOLDOWN_ID 1 #define BUTTON_SET_ID 2 #define BUTTON_PLAY_ID 3 #define BUTTON_MODE_ID 4 #define BUTTON_REC_ID 5 #define ES8311_MCLK_SOURCE 0 /* 0 From MCLK of esp32 1 From BCLK */ #define HEADPHONE_DETECT -1 #define PA_ENABLE_GPIO GPIO_NUM_48 // TCA9554 IO Pin number #define GREEN_LED_GPIO -1 #define BLUE_LED_GPIO BIT(7) #define RED_LED_GPIO BIT(6) // TCA9554 IO Pin number #define LCD_CTRL_GPIO BIT(1) #define LCD_RST_GPIO BIT(2) #define LCD_CS_GPIO BIT(3) #define ESP_SD_PIN_CLK GPIO_NUM_15 #define ESP_SD_PIN_CMD GPIO_NUM_7 #define ESP_SD_PIN_D0 GPIO_NUM_4 #define ESP_SD_PIN_D1 -1 #define ESP_SD_PIN_D2 -1 #define ESP_SD_PIN_D3 -1 #define ESP_SD_PIN_D4 -1 #define ESP_SD_PIN_D5 -1 #define ESP_SD_PIN_D6 -1 #define ESP_SD_PIN_D7 -1 #define ESP_SD_PIN_CD -1 #define ESP_SD_PIN_WP -1 extern audio_hal_func_t AUDIO_CODEC_ES8311_DEFAULT_HANDLE; extern audio_hal_func_t AUDIO_CODEC_ES7210_DEFAULT_HANDLE; #define AUDIO_CODEC_DEFAULT_CONFIG(){ \ .adc_input = AUDIO_HAL_ADC_INPUT_LINE1, \ .dac_output = AUDIO_HAL_DAC_OUTPUT_ALL, \ .codec_mode = AUDIO_HAL_CODEC_MODE_BOTH, \ .i2s_iface = { \ .mode = AUDIO_HAL_MODE_SLAVE, \ .fmt = AUDIO_HAL_I2S_NORMAL, \ .samples = AUDIO_HAL_48K_SAMPLES, \ .bits = AUDIO_HAL_BIT_LENGTH_16BITS, \ }, \ }; #define INPUT_KEY_NUM 6 #define INPUT_KEY_DEFAULT_INFO() { \ { \ .type = PERIPH_ID_ADC_BTN, \ .user_id = INPUT_KEY_USER_ID_REC, \ .act_id = BUTTON_REC_ID, \ }, \ { \ .type = PERIPH_ID_ADC_BTN, \ .user_id = INPUT_KEY_USER_ID_MUTE, \ .act_id = BUTTON_MODE_ID, \ }, \ { \ .type = PERIPH_ID_ADC_BTN, \ .user_id = INPUT_KEY_USER_ID_SET, \ .act_id = BUTTON_SET_ID, \ }, \ { \ .type = PERIPH_ID_ADC_BTN, \ .user_id = INPUT_KEY_USER_ID_PLAY, \ .act_id = BUTTON_PLAY_ID, \ }, \ { \ .type = PERIPH_ID_ADC_BTN, \ .user_id = INPUT_KEY_USER_ID_VOLUP, \ .act_id = BUTTON_VOLUP_ID, \ }, \ { \ .type = PERIPH_ID_ADC_BTN, \ .user_id = INPUT_KEY_USER_ID_VOLDOWN, \ .act_id = BUTTON_VOLDOWN_ID, \ } \ } #endif
YifuLiu/AliOS-Things
hardware/chip/espressif_adf/esp-adf/components/audio_board/esp32_s3_korvo2_v3/board_def.h
C
apache-2.0
5,198
/* * ESPRESSIF MIT License * * Copyright (c) 2021 <ESPRESSIF SYSTEMS (SHANGHAI) CO., LTD> * * Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case, * it is free of charge, to any person obtaining a copy of this software and associated * documentation files (the "Software"), to deal in the Software without restriction, including * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the Software is furnished * to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all copies or * substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * */ #include "esp_log.h" #include "driver/gpio.h" #include <string.h> #include "board.h" #include "audio_error.h" #include "audio_mem.h" static const char *TAG = "ESP32_S3_KORVO_2"; esp_err_t get_i2c_pins(i2c_port_t port, i2c_config_t *i2c_config) { AUDIO_NULL_CHECK(TAG, i2c_config, return ESP_FAIL); if (port == I2C_NUM_0 || port == I2C_NUM_1) { i2c_config->sda_io_num = GPIO_NUM_17; i2c_config->scl_io_num = GPIO_NUM_18; } else { i2c_config->sda_io_num = -1; i2c_config->scl_io_num = -1; ESP_LOGE(TAG, "i2c port %d is not supported", port); return ESP_FAIL; } return ESP_OK; } esp_err_t get_i2s_pins(i2s_port_t port, i2s_pin_config_t *i2s_config) { AUDIO_NULL_CHECK(TAG, i2s_config, return ESP_FAIL); if (port == I2S_NUM_0) { i2s_config->bck_io_num = GPIO_NUM_9; i2s_config->ws_io_num = GPIO_NUM_45; i2s_config->data_out_num = GPIO_NUM_8; i2s_config->data_in_num = GPIO_NUM_10; i2s_config->mck_io_num = GPIO_NUM_16; } else if (port == I2S_NUM_1) { i2s_config->bck_io_num = -1; i2s_config->ws_io_num = -1; i2s_config->data_out_num = -1; i2s_config->data_in_num = -1; i2s_config->mck_io_num = -1; } else { memset(i2s_config, -1, sizeof(i2s_pin_config_t)); ESP_LOGE(TAG, "i2s port %d is not supported", port); return ESP_FAIL; } return ESP_OK; } esp_err_t get_spi_pins(spi_bus_config_t *spi_config, spi_device_interface_config_t *spi_device_interface_config) { AUDIO_NULL_CHECK(TAG, spi_config, return ESP_FAIL); AUDIO_NULL_CHECK(TAG, spi_device_interface_config, return ESP_FAIL); spi_config->mosi_io_num = -1; spi_config->miso_io_num = -1; spi_config->sclk_io_num = -1; spi_config->quadwp_io_num = -1; spi_config->quadhd_io_num = -1; spi_device_interface_config->spics_io_num = -1; ESP_LOGW(TAG, "SPI interface is not supported"); return ESP_OK; } esp_err_t i2s_mclk_gpio_select(i2s_port_t i2s_num, gpio_num_t gpio_num) { if (i2s_num >= I2S_NUM_MAX) { ESP_LOGE(TAG, "Does not support i2s number(%d)", i2s_num); return ESP_ERR_INVALID_ARG; } ESP_LOGI(TAG, "I2S%d, MCLK output by GPIO%d", i2s_num, gpio_num); return ESP_OK; } // sdcard int8_t get_sdcard_intr_gpio(void) { return SDCARD_INTR_GPIO; } int8_t get_sdcard_open_file_num_max(void) { return SDCARD_OPEN_FILE_NUM_MAX; } int8_t get_sdcard_power_ctrl_gpio(void) { return SDCARD_PWR_CTRL; } // input-output pins int8_t get_headphone_detect_gpio(void) { return HEADPHONE_DETECT; } int8_t get_pa_enable_gpio(void) { return PA_ENABLE_GPIO; } // adc button id int8_t get_input_rec_id(void) { return BUTTON_REC_ID; } int8_t get_input_mode_id(void) { return BUTTON_MODE_ID; } int8_t get_input_set_id(void) { return BUTTON_SET_ID; } int8_t get_input_play_id(void) { return BUTTON_PLAY_ID; } int8_t get_input_volup_id(void) { return BUTTON_VOLUP_ID; } int8_t get_input_voldown_id(void) { return BUTTON_VOLDOWN_ID; } // led pins int8_t get_green_led_gpio(void) { return GREEN_LED_GPIO; } int8_t get_blue_led_gpio(void) { return BLUE_LED_GPIO; } int8_t get_es8311_mclk_src(void) { return ES8311_MCLK_SOURCE; }
YifuLiu/AliOS-Things
hardware/chip/espressif_adf/esp-adf/components/audio_board/esp32_s3_korvo2_v3/board_pins_config.c
C
apache-2.0
4,538
/* * ESPRESSIF MIT License * * Copyright (c) 2019 <ESPRESSIF SYSTEMS (SHANGHAI) CO., LTD> * * Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case, * it is free of charge, to any person obtaining a copy of this software and associated * documentation files (the "Software"), to deal in the Software without restriction, including * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the Software is furnished * to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all copies or * substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * */ #ifndef _BOARD_PINS_CONFIG_H_ #define _BOARD_PINS_CONFIG_H_ #include "driver/i2c.h" #include "driver/i2s.h" #include "driver/spi_common.h" #include "driver/spi_master.h" #include "driver/spi_slave.h" #ifdef __cplusplus extern "C" { #endif /** * @brief Get i2c pins configuration * * @param port i2c port number to get configuration * @param i2c_config i2c configuration parameters * * @return * - ESP_OK * - ESP_FAIL */ esp_err_t get_i2c_pins(i2c_port_t port, i2c_config_t *i2c_config); /** * @brief Get i2s pins configuration * * @param port i2s port number to get configuration * @param i2s_config i2s configuration parameters * * @return * - ESP_OK * - ESP_FAIL */ esp_err_t get_i2s_pins(i2s_port_t port, i2s_pin_config_t *i2s_config); /** * @brief Get spi pins configuration * * @param spi_config spi bus configuration parameters * @param spi_device_interface_config spi device configuration parameters * * @return * - ESP_OK * - ESP_FAIL */ esp_err_t get_spi_pins(spi_bus_config_t *spi_config, spi_device_interface_config_t *spi_device_interface_config); /** * @brief Set i2s mclk output pin * * @note GPIO1 and GPIO3 default are UART pins. * * @param i2s_num i2s port index * @param gpio_num gpio number index, only support GPIO0, GPIO1 and GPIO3. * @return * - ESP_OK Success * - ESP_ERR_INVALID_ARG Parameter error * - ESP_ERR_INVALID_STATE Driver state error * - ESP_ERR_ADF_NOT_SUPPORT Not support */ esp_err_t i2s_mclk_gpio_select(i2s_port_t i2s_num, gpio_num_t gpio_num); /** * @brief Get the gpio number for sdcard interrupt * * @return -1 non-existent * Others sdcard interrupt gpio number */ int8_t get_sdcard_intr_gpio(void); /** * @brief Get sdcard maximum number of open files * * @return -1 error * Others max num */ int8_t get_sdcard_open_file_num_max(void); /** * @brief Get the gpio number for auxin detection * * @return -1 non-existent * Others gpio number */ int8_t get_auxin_detect_gpio(void); /** * @brief Get the gpio number for headphone detection * * @return -1 non-existent * Others gpio number */ int8_t get_headphone_detect_gpio(void); /** * @brief Get the gpio number for PA enable * * @return -1 non-existent * Others gpio number */ int8_t get_pa_enable_gpio(void); /** * @brief Get the gpio number for adc detection * * @return -1 non-existent * Others gpio number */ int8_t get_adc_detect_gpio(void); /** * @brief Get the mclk gpio number of es7243 * * @return -1 non-existent * Others gpio number */ int8_t get_es7243_mclk_gpio(void); /** * @brief Get the record-button id for adc-button * * @return -1 non-existent * Others button id */ int8_t get_input_rec_id(void); /** * @brief Get the number for mode-button * * @return -1 non-existent * Others number */ int8_t get_input_mode_id(void); /** * @brief Get number for set function * * @return -1 non-existent * Others number */ int8_t get_input_set_id(void); /** * @brief Get number for play function * * @return -1 non-existent * Others number */ int8_t get_input_play_id(void); /** * @brief number for volume up function * * @return -1 non-existent * Others number */ int8_t get_input_volup_id(void); /** * @brief Get number for volume down function * * @return -1 non-existent * Others number */ int8_t get_input_voldown_id(void); /** * @brief Get green led gpio number * * @return -1 non-existent * Others gpio number */ int8_t get_reset_codec_gpio(void); /** * @brief Get DSP reset gpio number * * @return -1 non-existent * Others gpio number */ int8_t get_reset_board_gpio(void); /** * @brief Get DSP reset gpio number * * @return -1 non-existent * Others gpio number */ int8_t get_green_led_gpio(void); /** * @brief Get green led gpio number * * @return -1 non-existent * Others gpio number */ int8_t get_blue_led_gpio(void); #ifdef __cplusplus } #endif #endif
YifuLiu/AliOS-Things
hardware/chip/espressif_adf/esp-adf/components/audio_board/include/board_pins_config.h
C
apache-2.0
5,627
/* * ESPRESSIF MIT License * * Copyright (c) 2019 <ESPRESSIF SYSTEMS (SHANGHAI) CO., LTD> * * Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case, * it is free of charge, to any person obtaining a copy of this software and associated * documentation files (the "Software"), to deal in the Software without restriction, including * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the Software is furnished * to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all copies or * substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * */ #include "esp_log.h" #include "board.h" #include "audio_mem.h" #include "periph_sdcard.h" #include "led_indicator.h" #include "periph_adc_button.h" static const char *TAG = "AUDIO_BOARD"; static audio_board_handle_t board_handle = 0; audio_board_handle_t audio_board_init(void) { if (board_handle) { ESP_LOGW(TAG, "The board has already been initialized!"); return board_handle; } board_handle = (audio_board_handle_t) audio_calloc(1, sizeof(struct audio_board_handle)); AUDIO_MEM_CHECK(TAG, board_handle, return NULL); board_handle->audio_hal = audio_board_codec_init(); board_handle->adc_hal = audio_board_adc_init(); return board_handle; } audio_hal_handle_t audio_board_adc_init(void) { audio_hal_codec_config_t audio_codec_cfg = AUDIO_CODEC_DEFAULT_CONFIG(); audio_hal_handle_t adc_hal = audio_hal_init(&audio_codec_cfg, &AUDIO_CODEC_ES7243_DEFAULT_HANDLE); AUDIO_NULL_CHECK(TAG, adc_hal, return NULL); return adc_hal; } audio_hal_handle_t audio_board_codec_init(void) { audio_hal_codec_config_t audio_codec_cfg = AUDIO_CODEC_DEFAULT_CONFIG(); audio_hal_handle_t codec_hal = audio_hal_init(&audio_codec_cfg, &AUDIO_CODEC_ES8311_DEFAULT_HANDLE); AUDIO_NULL_CHECK(TAG, codec_hal, return NULL); return codec_hal; } display_service_handle_t audio_board_led_init(void) { led_indicator_handle_t led = led_indicator_init((gpio_num_t)get_green_led_gpio()); display_service_config_t display = { .based_cfg = { .task_stack = 0, .task_prio = 0, .task_core = 0, .task_func = NULL, .service_start = NULL, .service_stop = NULL, .service_destroy = NULL, .service_ioctl = led_indicator_pattern, .service_name = "DISPLAY_serv", .user_data = NULL, }, .instance = led, }; return display_service_create(&display); } display_service_handle_t audio_board_blue_led_init(void) { led_indicator_handle_t led = led_indicator_init((gpio_num_t)get_blue_led_gpio()); display_service_config_t display = { .based_cfg = { .task_stack = 0, .task_prio = 0, .task_core = 0, .task_func = NULL, .service_start = NULL, .service_stop = NULL, .service_destroy = NULL, .service_ioctl = led_indicator_pattern, .service_name = "DISPLAY_serv", .user_data = NULL, }, .instance = led, }; return display_service_create(&display); } esp_err_t audio_board_key_init(esp_periph_set_handle_t set) { esp_err_t ret = ESP_OK; periph_adc_button_cfg_t adc_btn_cfg = PERIPH_ADC_BUTTON_DEFAULT_CONFIG(); adc_arr_t adc_btn_tag = ADC_DEFAULT_ARR(); adc_btn_tag.total_steps = 6; int btn_array[7] = {190, 600, 1000, 1375, 1775, 2195, 3100}; adc_btn_tag.adc_level_step = btn_array; adc_btn_cfg.arr = &adc_btn_tag; adc_btn_cfg.arr_size = 1; esp_periph_handle_t adc_btn_handle = periph_adc_button_init(&adc_btn_cfg); AUDIO_NULL_CHECK(TAG, adc_btn_handle, return ESP_ERR_ADF_MEMORY_LACK); ret = esp_periph_start(set, adc_btn_handle); return ret; } esp_err_t audio_board_sdcard_init(esp_periph_set_handle_t set, periph_sdcard_mode_t mode) { if (mode != SD_MODE_1_LINE) { ESP_LOGE(TAG, "current board only support 1-line SD mode!"); return ESP_FAIL; } gpio_config_t sdcard_pwr_pin_cfg = { .pin_bit_mask = 1UL << SDCARD_PWR_CTRL, .mode = GPIO_MODE_OUTPUT, .pull_up_en = GPIO_PULLUP_DISABLE, .pull_down_en = GPIO_PULLDOWN_DISABLE, .intr_type = GPIO_INTR_DISABLE, }; gpio_config(&sdcard_pwr_pin_cfg); gpio_set_level(SDCARD_PWR_CTRL, 0); periph_sdcard_cfg_t sdcard_cfg = { .root = "/sdcard", .card_detect_pin = get_sdcard_intr_gpio(), // GPIO_NUM_34 .mode = mode }; esp_periph_handle_t sdcard_handle = periph_sdcard_init(&sdcard_cfg); esp_err_t ret = esp_periph_start(set, sdcard_handle); int retry_time = 5; bool mount_flag = false; while (retry_time --) { if (periph_sdcard_is_mounted(sdcard_handle)) { mount_flag = true; break; } else { vTaskDelay(500 / portTICK_PERIOD_MS); } } if (mount_flag == false) { ESP_LOGE(TAG, "Sdcard mount failed"); return ESP_FAIL; } return ret; } audio_board_handle_t audio_board_get_handle(void) { return board_handle; } esp_err_t audio_board_deinit(audio_board_handle_t audio_board) { esp_err_t ret = ESP_OK; ret |= audio_hal_deinit(audio_board->audio_hal); ret |= audio_hal_deinit(audio_board->adc_hal); audio_free(audio_board); board_handle = NULL; return ret; }
YifuLiu/AliOS-Things
hardware/chip/espressif_adf/esp-adf/components/audio_board/lyrat_mini_v1_1/board.c
C
apache-2.0
6,085
/* * ESPRESSIF MIT License * * Copyright (c) 2019 <ESPRESSIF SYSTEMS (SHANGHAI) CO., LTD> * * Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case, * it is free of charge, to any person obtaining a copy of this software and associated * documentation files (the "Software"), to deal in the Software without restriction, including * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the Software is furnished * to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all copies or * substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * */ #ifndef _AUDIO_BOARD_H_ #define _AUDIO_BOARD_H_ #include "audio_hal.h" #include "board_def.h" #include "board_pins_config.h" #include "esp_peripherals.h" #include "display_service.h" #include "periph_sdcard.h" #ifdef __cplusplus extern "C" { #endif /** * @brief Audio board handle */ struct audio_board_handle { audio_hal_handle_t audio_hal; /*!< audio hardware abstract layer handle */ audio_hal_handle_t adc_hal; /*!< adc hardware abstract layer handle */ }; typedef struct audio_board_handle *audio_board_handle_t; /** * @brief Initialize audio board * * @return The audio board handle */ audio_board_handle_t audio_board_init(void); /** * @brief Initialize codec chip * * @return The audio hal handle */ audio_hal_handle_t audio_board_codec_init(void); /** * @brief Initialize adc * * @return The adc hal handle */ audio_hal_handle_t audio_board_adc_init(void); /** * @brief Initialize led peripheral and display service * * @return The audio display service handle */ display_service_handle_t audio_board_led_init(void); /** * @brief Initialize led peripheral and display service * * @return The audio display service handle */ display_service_handle_t audio_board_blue_led_init(void); /** * @brief Initialize key peripheral * * @param set The handle of esp_periph_set_handle_t * * @return * - ESP_OK, success * - Others, fail */ esp_err_t audio_board_key_init(esp_periph_set_handle_t set); /** * @brief Initialize sdcard peripheral * * @param set The handle of esp_periph_set_handle_t * * @return * - ESP_OK, success * - Others, fail */ esp_err_t audio_board_sdcard_init(esp_periph_set_handle_t set, periph_sdcard_mode_t mode); /** * @brief Query audio_board_handle * * @return The audio board handle */ audio_board_handle_t audio_board_get_handle(void); /** * @brief Uninitialize the audio board * * @param audio_board The handle of audio board * * @return 0 success, * others fail */ esp_err_t audio_board_deinit(audio_board_handle_t audio_board); #ifdef __cplusplus } #endif #endif
YifuLiu/AliOS-Things
hardware/chip/espressif_adf/esp-adf/components/audio_board/lyrat_mini_v1_1/board.h
C
apache-2.0
3,334
/* * ESPRESSIF MIT License * * Copyright (c) 2019 <ESPRESSIF SYSTEMS (SHANGHAI) CO., LTD> * * Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case, * it is free of charge, to any person obtaining a copy of this software and associated * documentation files (the "Software"), to deal in the Software without restriction, including * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the Software is furnished * to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all copies or * substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * */ #ifndef _AUDIO_BOARD_DEFINITION_H_ #define _AUDIO_BOARD_DEFINITION_H_ #define SDCARD_OPEN_FILE_NUM_MAX 5 #define SDCARD_INTR_GPIO GPIO_NUM_34 #define SDCARD_PWR_CTRL GPIO_NUM_13 #define ES7243_MCLK_GPIO GPIO_NUM_0 #define BUTTON_VOLUP_ID 0 #define BUTTON_VOLDOWN_ID 1 #define BUTTON_SET_ID 2 #define BUTTON_PLAY_ID 3 #define BUTTON_MODE_ID 4 #define BUTTON_REC_ID 5 #define ES8311_MCLK_SOURCE 0 /* 0 From MCLK of esp32 1 From BCLK */ #define HEADPHONE_DETECT GPIO_NUM_19 #define PA_ENABLE_GPIO GPIO_NUM_21 #define BLUE_LED_GPIO GPIO_NUM_27 #define GREEN_LED_GPIO GPIO_NUM_22 extern audio_hal_func_t AUDIO_CODEC_ES8311_DEFAULT_HANDLE; extern audio_hal_func_t AUDIO_CODEC_ES7243_DEFAULT_HANDLE; #define AUDIO_CODEC_DEFAULT_CONFIG(){ \ .adc_input = AUDIO_HAL_ADC_INPUT_LINE1, \ .dac_output = AUDIO_HAL_DAC_OUTPUT_ALL, \ .codec_mode = AUDIO_HAL_CODEC_MODE_BOTH, \ .i2s_iface = { \ .mode = AUDIO_HAL_MODE_SLAVE, \ .fmt = AUDIO_HAL_I2S_NORMAL, \ .samples = AUDIO_HAL_48K_SAMPLES, \ .bits = AUDIO_HAL_BIT_LENGTH_16BITS, \ }, \ }; #define INPUT_KEY_NUM 6 #define INPUT_KEY_DEFAULT_INFO() { \ { \ .type = PERIPH_ID_ADC_BTN, \ .user_id = INPUT_KEY_USER_ID_REC, \ .act_id = BUTTON_REC_ID, \ }, \ { \ .type = PERIPH_ID_ADC_BTN, \ .user_id = INPUT_KEY_USER_ID_MODE, \ .act_id = BUTTON_MODE_ID, \ }, \ { \ .type = PERIPH_ID_ADC_BTN, \ .user_id = INPUT_KEY_USER_ID_SET, \ .act_id = BUTTON_SET_ID, \ }, \ { \ .type = PERIPH_ID_ADC_BTN, \ .user_id = INPUT_KEY_USER_ID_PLAY, \ .act_id = BUTTON_PLAY_ID, \ }, \ { \ .type = PERIPH_ID_ADC_BTN, \ .user_id = INPUT_KEY_USER_ID_VOLUP, \ .act_id = BUTTON_VOLUP_ID, \ }, \ { \ .type = PERIPH_ID_ADC_BTN, \ .user_id = INPUT_KEY_USER_ID_VOLDOWN, \ .act_id = BUTTON_VOLDOWN_ID, \ } \ } #endif
YifuLiu/AliOS-Things
hardware/chip/espressif_adf/esp-adf/components/audio_board/lyrat_mini_v1_1/board_def.h
C
apache-2.0
4,505
/* * ESPRESSIF MIT License * * Copyright (c) 2019 <ESPRESSIF SYSTEMS (SHANGHAI) CO., LTD> * * Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case, * it is free of charge, to any person obtaining a copy of this software and associated * documentation files (the "Software"), to deal in the Software without restriction, including * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the Software is furnished * to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all copies or * substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * */ #include "esp_log.h" #include "driver/gpio.h" #include <string.h> #include "board.h" #include "audio_error.h" #include "audio_mem.h" static const char *TAG = "LYRAT_MINI_V1_1"; esp_err_t get_i2c_pins(i2c_port_t port, i2c_config_t *i2c_config) { AUDIO_NULL_CHECK(TAG, i2c_config, return ESP_FAIL); if (port == I2C_NUM_0 || port == I2C_NUM_1) { i2c_config->sda_io_num = GPIO_NUM_18; i2c_config->scl_io_num = GPIO_NUM_23; } else { i2c_config->sda_io_num = -1; i2c_config->scl_io_num = -1; ESP_LOGE(TAG, "i2c port %d is not supported", port); return ESP_FAIL; } return ESP_OK; } esp_err_t get_i2s_pins(i2s_port_t port, i2s_pin_config_t *i2s_config) { AUDIO_NULL_CHECK(TAG, i2s_config, return ESP_FAIL); if (port == I2S_NUM_0) { i2s_config->bck_io_num = GPIO_NUM_5; i2s_config->ws_io_num = GPIO_NUM_25; i2s_config->data_out_num = GPIO_NUM_26; i2s_config->data_in_num = GPIO_NUM_35; } else if (port == I2S_NUM_1) { i2s_config->bck_io_num = GPIO_NUM_32; i2s_config->ws_io_num = GPIO_NUM_33; i2s_config->data_out_num = -1; i2s_config->data_in_num = GPIO_NUM_36; } else { memset(i2s_config, -1, sizeof(i2s_pin_config_t)); ESP_LOGE(TAG, "i2s port %d is not supported", port); return ESP_FAIL; } return ESP_OK; } esp_err_t get_spi_pins(spi_bus_config_t *spi_config, spi_device_interface_config_t *spi_device_interface_config) { AUDIO_NULL_CHECK(TAG, spi_config, return ESP_FAIL); AUDIO_NULL_CHECK(TAG, spi_device_interface_config, return ESP_FAIL); spi_config->mosi_io_num = -1; spi_config->miso_io_num = -1; spi_config->sclk_io_num = -1; spi_config->quadwp_io_num = -1; spi_config->quadhd_io_num = -1; spi_device_interface_config->spics_io_num = -1; ESP_LOGW(TAG, "SPI interface is not supported"); return ESP_OK; } esp_err_t i2s_mclk_gpio_select(i2s_port_t i2s_num, gpio_num_t gpio_num) { if (i2s_num >= I2S_NUM_MAX) { ESP_LOGE(TAG, "Does not support i2s number(%d)", i2s_num); return ESP_ERR_INVALID_ARG; } if (gpio_num != GPIO_NUM_0 && gpio_num != GPIO_NUM_1 && gpio_num != GPIO_NUM_3) { ESP_LOGE(TAG, "Only support GPIO0/GPIO1/GPIO3, gpio_num:%d", gpio_num); return ESP_ERR_INVALID_ARG; } ESP_LOGI(TAG, "I2S%d, MCLK output by GPIO%d", i2s_num, gpio_num); if (i2s_num == I2S_NUM_0) { if (gpio_num == GPIO_NUM_0) { PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO0_U, FUNC_GPIO0_CLK_OUT1); WRITE_PERI_REG(PIN_CTRL, 0xFFF0); } else if (gpio_num == GPIO_NUM_1) { PIN_FUNC_SELECT(PERIPHS_IO_MUX_U0TXD_U, FUNC_U0TXD_CLK_OUT3); WRITE_PERI_REG(PIN_CTRL, 0xF0F0); } else { PIN_FUNC_SELECT(PERIPHS_IO_MUX_U0RXD_U, FUNC_U0RXD_CLK_OUT2); WRITE_PERI_REG(PIN_CTRL, 0xFF00); } } else if (i2s_num == I2S_NUM_1) { if (gpio_num == GPIO_NUM_0) { PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO0_U, FUNC_GPIO0_CLK_OUT1); WRITE_PERI_REG(PIN_CTRL, 0xFFFF); } else if (gpio_num == GPIO_NUM_1) { PIN_FUNC_SELECT(PERIPHS_IO_MUX_U0TXD_U, FUNC_U0TXD_CLK_OUT3); WRITE_PERI_REG(PIN_CTRL, 0xF0FF); } else { PIN_FUNC_SELECT(PERIPHS_IO_MUX_U0RXD_U, FUNC_U0RXD_CLK_OUT2); WRITE_PERI_REG(PIN_CTRL, 0xFF0F); } } return ESP_OK; } // sdcard int8_t get_sdcard_intr_gpio(void) { return SDCARD_INTR_GPIO; } int8_t get_sdcard_open_file_num_max(void) { return SDCARD_OPEN_FILE_NUM_MAX; } int8_t get_sdcard_power_ctrl_gpio(void) { return SDCARD_PWR_CTRL; } // input-output pins int8_t get_headphone_detect_gpio(void) { return HEADPHONE_DETECT; } int8_t get_pa_enable_gpio(void) { return PA_ENABLE_GPIO; } // adc button id int8_t get_input_rec_id(void) { return BUTTON_REC_ID; } int8_t get_input_mode_id(void) { return BUTTON_MODE_ID; } int8_t get_input_set_id(void) { return BUTTON_SET_ID; } int8_t get_input_play_id(void) { return BUTTON_PLAY_ID; } int8_t get_input_volup_id(void) { return BUTTON_VOLUP_ID; } int8_t get_input_voldown_id(void) { return BUTTON_VOLDOWN_ID; } // led pins int8_t get_green_led_gpio(void) { return GREEN_LED_GPIO; } int8_t get_blue_led_gpio(void) { return BLUE_LED_GPIO; } int8_t get_es8311_mclk_src(void) { return ES8311_MCLK_SOURCE; } int8_t get_es7243_mclk_gpio(void) { return ES7243_MCLK_GPIO; }
YifuLiu/AliOS-Things
hardware/chip/espressif_adf/esp-adf/components/audio_board/lyrat_mini_v1_1/board_pins_config.c
C
apache-2.0
5,775
/* * ESPRESSIF MIT License * * Copyright (c) 2019 <ESPRESSIF SYSTEMS (SHANGHAI) CO., LTD> * * Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case, * it is free of charge, to any person obtaining a copy of this software and associated * documentation files (the "Software"), to deal in the Software without restriction, including * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the Software is furnished * to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all copies or * substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * */ #include "esp_log.h" #include "board.h" #include "audio_mem.h" static const char *TAG = "AUDIO_BOARD"; static audio_board_handle_t board_handle = 0; audio_board_handle_t audio_board_init(void) { if (board_handle) { ESP_LOGW(TAG, "The board has already been initialized!"); return board_handle; } audio_hal_codec_config_t audio_codec_cfg = AUDIO_CODEC_DEFAULT_CONFIG(); board_handle = (audio_board_handle_t) audio_calloc(1, sizeof(struct audio_board_handle)); AUDIO_MEM_CHECK(TAG, board_handle, return NULL); board_handle->audio_hal = audio_hal_init(&audio_codec_cfg, &AUDIO_CODEC_ES8388_DEFAULT_HANDLE); return board_handle; } audio_board_handle_t audio_board_get_handle(void) { return board_handle; } esp_err_t audio_board_deinit(audio_board_handle_t audio_board) { esp_err_t ret = ESP_OK; ret = audio_hal_deinit(audio_board->audio_hal); audio_free(audio_board); board_handle = NULL; return ret; }
YifuLiu/AliOS-Things
hardware/chip/espressif_adf/esp-adf/components/audio_board/lyrat_v4_2/board.c
C
apache-2.0
2,210
/* * ESPRESSIF MIT License * * Copyright (c) 2019 <ESPRESSIF SYSTEMS (SHANGHAI) CO., LTD> * * Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case, * it is free of charge, to any person obtaining a copy of this software and associated * documentation files (the "Software"), to deal in the Software without restriction, including * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the Software is furnished * to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all copies or * substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * */ #ifndef _AUDIO_BOARD_H_ #define _AUDIO_BOARD_H_ #include "audio_hal.h" #include "board_def.h" #include "board_pins_config.h" #include "esp_peripherals.h" #include "display_service.h" #include "periph_sdcard.h" #ifdef __cplusplus extern "C" { #endif /** * @brief Audio board handle */ struct audio_board_handle { audio_hal_handle_t audio_hal; /*!< audio hardware abstract layer handle */ }; typedef struct audio_board_handle *audio_board_handle_t; /** * @brief Initialize audio board * * @return The audio board handle */ audio_board_handle_t audio_board_init(void); /** * @brief Initialize codec chip * * @return The audio hal handle */ audio_hal_handle_t audio_board_codec_init(void); /** * @brief Initialize led peripheral and display service * * @return The audio display service handle */ display_service_handle_t audio_board_led_init(void); /** * @brief Initialize key peripheral * * @param set The handle of esp_periph_set_handle_t * * @return * - ESP_OK, success * - Others, fail */ esp_err_t audio_board_key_init(esp_periph_set_handle_t set); /** * @brief Initialize sdcard peripheral * * @param set The handle of esp_periph_set_handle_t * * @return * - ESP_OK, success * - Others, fail */ esp_err_t audio_board_sdcard_init(esp_periph_set_handle_t set, periph_sdcard_mode_t mode); /** * @brief Query audio_board_handle * * @return The audio board handle */ audio_board_handle_t audio_board_get_handle(void); /** * @brief Uninitialize the audio board * * @param audio_board The handle of audio board * * @return 0 success, * others fail */ esp_err_t audio_board_deinit(audio_board_handle_t audio_board); #ifdef __cplusplus } #endif #endif
YifuLiu/AliOS-Things
hardware/chip/espressif_adf/esp-adf/components/audio_board/lyrat_v4_2/board.h
C
apache-2.0
2,973
/* * ESPRESSIF MIT License * * Copyright (c) 2019 <ESPRESSIF SYSTEMS (SHANGHAI) CO., LTD> * * Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case, * it is free of charge, to any person obtaining a copy of this software and associated * documentation files (the "Software"), to deal in the Software without restriction, including * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the Software is furnished * to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all copies or * substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * */ #ifndef _AUDIO_BOARD_DEFINITION_H_ #define _AUDIO_BOARD_DEFINITION_H_ #include "driver/touch_pad.h" #define SDCARD_OPEN_FILE_NUM_MAX 5 #define SDCARD_INTR_GPIO GPIO_NUM_34 #define BUTTON_REC_ID GPIO_NUM_36 #define BUTTON_MODE_ID GPIO_NUM_39 #define BUTTON_SET_ID TOUCH_PAD_NUM9 #define BUTTON_PLAY_ID TOUCH_PAD_NUM8 #define BUTTON_VOLUP_ID TOUCH_PAD_NUM7 #define BUTTON_VOLDOWN_ID TOUCH_PAD_NUM4 #define AUXIN_DETECT_GPIO GPIO_NUM_12 #define PA_ENABLE_GPIO GPIO_NUM_21 #define GREEN_LED_GPIO GPIO_NUM_22 #define RED_LED_GPIO GPIO_NUM_19 extern audio_hal_func_t AUDIO_CODEC_ES8388_DEFAULT_HANDLE; #define AUDIO_CODEC_DEFAULT_CONFIG(){ \ .adc_input = AUDIO_HAL_ADC_INPUT_LINE1, \ .dac_output = AUDIO_HAL_DAC_OUTPUT_ALL, \ .codec_mode = AUDIO_HAL_CODEC_MODE_BOTH, \ .i2s_iface = { \ .mode = AUDIO_HAL_MODE_SLAVE, \ .fmt = AUDIO_HAL_I2S_NORMAL, \ .samples = AUDIO_HAL_48K_SAMPLES, \ .bits = AUDIO_HAL_BIT_LENGTH_16BITS, \ }, \ }; #define INPUT_KEY_NUM 6 #define INPUT_KEY_DEFAULT_INFO() { \ { \ .type = PERIPH_ID_BUTTON, \ .user_id = INPUT_KEY_USER_ID_REC, \ .act_id = BUTTON_REC_ID, \ }, \ { \ .type = PERIPH_ID_BUTTON, \ .user_id = INPUT_KEY_USER_ID_MODE, \ .act_id = BUTTON_MODE_ID, \ }, \ { \ .type = PERIPH_ID_TOUCH, \ .user_id = INPUT_KEY_USER_ID_SET, \ .act_id = BUTTON_SET_ID, \ }, \ { \ .type = PERIPH_ID_TOUCH, \ .user_id = INPUT_KEY_USER_ID_PLAY, \ .act_id = BUTTON_PLAY_ID, \ }, \ { \ .type = PERIPH_ID_TOUCH, \ .user_id = INPUT_KEY_USER_ID_VOLUP, \ .act_id = BUTTON_VOLUP_ID, \ }, \ { \ .type = PERIPH_ID_TOUCH, \ .user_id = INPUT_KEY_USER_ID_VOLDOWN, \ .act_id = BUTTON_VOLDOWN_ID, \ } \ } #endif
YifuLiu/AliOS-Things
hardware/chip/espressif_adf/esp-adf/components/audio_board/lyrat_v4_2/board_def.h
C
apache-2.0
4,377
/* * ESPRESSIF MIT License * * Copyright (c) 2019 <ESPRESSIF SYSTEMS (SHANGHAI) CO., LTD> * * Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case, * it is free of charge, to any person obtaining a copy of this software and associated * documentation files (the "Software"), to deal in the Software without restriction, including * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the Software is furnished * to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all copies or * substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * */ #include "esp_log.h" #include "driver/gpio.h" #include <string.h> #include "board.h" #include "audio_error.h" #include "audio_mem.h" static const char *TAG = "LYRAT_V4_2"; esp_err_t get_i2c_pins(i2c_port_t port, i2c_config_t *i2c_config) { AUDIO_NULL_CHECK(TAG, i2c_config, return ESP_FAIL); if (port == I2C_NUM_0 || port == I2C_NUM_1) { i2c_config->sda_io_num = GPIO_NUM_18; i2c_config->scl_io_num = GPIO_NUM_23; } else { i2c_config->sda_io_num = -1; i2c_config->scl_io_num = -1; ESP_LOGE(TAG, "i2c port %d is not supported", port); return ESP_FAIL; } return ESP_OK; } esp_err_t get_i2s_pins(i2s_port_t port, i2s_pin_config_t *i2s_config) { AUDIO_NULL_CHECK(TAG, i2s_config, return ESP_FAIL); if (port == I2S_NUM_0 || port == I2S_NUM_1) { i2s_config->bck_io_num = GPIO_NUM_5; i2s_config->ws_io_num = GPIO_NUM_25; i2s_config->data_out_num = GPIO_NUM_26; i2s_config->data_in_num = GPIO_NUM_35; } else { memset(i2s_config, -1, sizeof(i2s_pin_config_t)); ESP_LOGE(TAG, "i2s port %d is not supported", port); return ESP_FAIL; } return ESP_OK; } esp_err_t get_spi_pins(spi_bus_config_t *spi_config, spi_device_interface_config_t *spi_device_interface_config) { AUDIO_NULL_CHECK(TAG, spi_config, return ESP_FAIL); AUDIO_NULL_CHECK(TAG, spi_device_interface_config, return ESP_FAIL); spi_config->mosi_io_num = -1; spi_config->miso_io_num = -1; spi_config->sclk_io_num = -1; spi_config->quadwp_io_num = -1; spi_config->quadhd_io_num = -1; spi_device_interface_config->spics_io_num = -1; ESP_LOGW(TAG, "SPI interface is not is not supported"); return ESP_OK; } esp_err_t i2s_mclk_gpio_select(i2s_port_t i2s_num, gpio_num_t gpio_num) { if (i2s_num >= I2S_NUM_MAX) { ESP_LOGE(TAG, "Does not support i2s number(%d)", i2s_num); return ESP_ERR_INVALID_ARG; } if (gpio_num != GPIO_NUM_0 && gpio_num != GPIO_NUM_1 && gpio_num != GPIO_NUM_3) { ESP_LOGE(TAG, "Only support GPIO0/GPIO1/GPIO3, gpio_num:%d", gpio_num); return ESP_ERR_INVALID_ARG; } ESP_LOGI(TAG, "I2S%d, MCLK output by GPIO%d", i2s_num, gpio_num); if (i2s_num == I2S_NUM_0) { if (gpio_num == GPIO_NUM_0) { PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO0_U, FUNC_GPIO0_CLK_OUT1); WRITE_PERI_REG(PIN_CTRL, 0xFFF0); } else if (gpio_num == GPIO_NUM_1) { PIN_FUNC_SELECT(PERIPHS_IO_MUX_U0TXD_U, FUNC_U0TXD_CLK_OUT3); WRITE_PERI_REG(PIN_CTRL, 0xF0F0); } else { PIN_FUNC_SELECT(PERIPHS_IO_MUX_U0RXD_U, FUNC_U0RXD_CLK_OUT2); WRITE_PERI_REG(PIN_CTRL, 0xFF00); } } else if (i2s_num == I2S_NUM_1) { if (gpio_num == GPIO_NUM_0) { PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO0_U, FUNC_GPIO0_CLK_OUT1); WRITE_PERI_REG(PIN_CTRL, 0xFFFF); } else if (gpio_num == GPIO_NUM_1) { PIN_FUNC_SELECT(PERIPHS_IO_MUX_U0TXD_U, FUNC_U0TXD_CLK_OUT3); WRITE_PERI_REG(PIN_CTRL, 0xF0FF); } else { PIN_FUNC_SELECT(PERIPHS_IO_MUX_U0RXD_U, FUNC_U0RXD_CLK_OUT2); WRITE_PERI_REG(PIN_CTRL, 0xFF0F); } } return ESP_OK; } // sdcard int8_t get_sdcard_intr_gpio(void) { return SDCARD_INTR_GPIO; } int8_t get_sdcard_open_file_num_max(void) { return SDCARD_OPEN_FILE_NUM_MAX; } // input-output pins int8_t get_auxin_detect_gpio(void) { return AUXIN_DETECT_GPIO; } int8_t get_pa_enable_gpio(void) { return PA_ENABLE_GPIO; } // button pins int8_t get_input_rec_id(void) { return BUTTON_REC_ID; } int8_t get_input_mode_id(void) { return BUTTON_MODE_ID; } // touch pins int8_t get_input_set_id(void) { return BUTTON_SET_ID; } int8_t get_input_play_id(void) { return BUTTON_PLAY_ID; } int8_t get_input_volup_id(void) { return BUTTON_VOLUP_ID; } int8_t get_input_voldown_id(void) { return BUTTON_VOLDOWN_ID; } // led pins int8_t get_red_led_gpio(void) { return RED_LED_GPIO; } int8_t get_green_led_gpio(void) { return GREEN_LED_GPIO; }
YifuLiu/AliOS-Things
hardware/chip/espressif_adf/esp-adf/components/audio_board/lyrat_v4_2/board_pins_config.c
C
apache-2.0
5,382
/* * ESPRESSIF MIT License * * Copyright (c) 2019 <ESPRESSIF SYSTEMS (SHANGHAI) CO., LTD> * * Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case, * it is free of charge, to any person obtaining a copy of this software and associated * documentation files (the "Software"), to deal in the Software without restriction, including * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the Software is furnished * to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all copies or * substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * */ #include "esp_log.h" #include "board.h" #include "audio_mem.h" #include "periph_sdcard.h" #include "led_indicator.h" #include "periph_touch.h" #include "periph_button.h" static const char *TAG = "AUDIO_BOARD"; static audio_board_handle_t board_handle = 0; audio_board_handle_t audio_board_init(void) { if (board_handle) { ESP_LOGW(TAG, "The board has already been initialized!"); return board_handle; } board_handle = (audio_board_handle_t) audio_calloc(1, sizeof(struct audio_board_handle)); AUDIO_MEM_CHECK(TAG, board_handle, return NULL); board_handle->audio_hal = audio_board_codec_init(); return board_handle; } audio_hal_handle_t audio_board_codec_init(void) { audio_hal_codec_config_t audio_codec_cfg = AUDIO_CODEC_DEFAULT_CONFIG(); audio_hal_handle_t codec_hal = audio_hal_init(&audio_codec_cfg, &AUDIO_CODEC_ES8388_DEFAULT_HANDLE); AUDIO_NULL_CHECK(TAG, codec_hal, return NULL); return codec_hal; } display_service_handle_t audio_board_led_init(void) { led_indicator_handle_t led = led_indicator_init((gpio_num_t)get_green_led_gpio()); display_service_config_t display = { .based_cfg = { .task_stack = 0, .task_prio = 0, .task_core = 0, .task_func = NULL, .service_start = NULL, .service_stop = NULL, .service_destroy = NULL, .service_ioctl = led_indicator_pattern, .service_name = "DISPLAY_serv", .user_data = NULL, }, .instance = led, }; return display_service_create(&display); } esp_err_t audio_board_key_init(esp_periph_set_handle_t set) { periph_button_cfg_t btn_cfg = { .gpio_mask = (1ULL << get_input_rec_id()) | (1ULL << get_input_mode_id()), //REC BTN & MODE BTN }; esp_periph_handle_t button_handle = periph_button_init(&btn_cfg); AUDIO_NULL_CHECK(TAG, button_handle, return ESP_ERR_ADF_MEMORY_LACK); esp_err_t ret = ESP_OK; ret = esp_periph_start(set, button_handle); if (ret != ESP_OK) { return ret; } periph_touch_cfg_t touch_cfg = { .touch_mask = TOUCH_PAD_SEL4 | TOUCH_PAD_SEL7 | TOUCH_PAD_SEL8 | TOUCH_PAD_SEL9, .tap_threshold_percent = 70, }; esp_periph_handle_t touch_periph = periph_touch_init(&touch_cfg); AUDIO_NULL_CHECK(TAG, touch_periph, return ESP_ERR_ADF_MEMORY_LACK); ret = esp_periph_start(set, touch_periph); return ret; } esp_err_t audio_board_sdcard_init(esp_periph_set_handle_t set, periph_sdcard_mode_t mode) { if (mode >= SD_MODE_MAX) { ESP_LOGE(TAG, "PLease select the correct sd mode!, current mode is %d", mode); return ESP_FAIL; } periph_sdcard_cfg_t sdcard_cfg = { .root = "/sdcard", .card_detect_pin = get_sdcard_intr_gpio(), // GPIO_NUM_34 .mode = mode, }; esp_periph_handle_t sdcard_handle = periph_sdcard_init(&sdcard_cfg); esp_err_t ret = esp_periph_start(set, sdcard_handle); int retry_time = 5; bool mount_flag = false; while (retry_time --) { if (periph_sdcard_is_mounted(sdcard_handle)) { mount_flag = true; break; } else { vTaskDelay(500 / portTICK_PERIOD_MS); } } if (mount_flag == false) { ESP_LOGE(TAG, "Sdcard mount failed"); return ESP_FAIL; } return ret; } audio_board_handle_t audio_board_get_handle(void) { return board_handle; } esp_err_t audio_board_deinit(audio_board_handle_t audio_board) { esp_err_t ret = ESP_OK; ret = audio_hal_deinit(audio_board->audio_hal); audio_free(audio_board); board_handle = NULL; return ret; }
YifuLiu/AliOS-Things
hardware/chip/espressif_adf/esp-adf/components/audio_board/lyrat_v4_3/board.c
C
apache-2.0
4,941
/* * ESPRESSIF MIT License * * Copyright (c) 2019 <ESPRESSIF SYSTEMS (SHANGHAI) CO., LTD> * * Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case, * it is free of charge, to any person obtaining a copy of this software and associated * documentation files (the "Software"), to deal in the Software without restriction, including * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the Software is furnished * to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all copies or * substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * */ #ifndef _AUDIO_BOARD_H_ #define _AUDIO_BOARD_H_ #include "audio_hal.h" #include "board_def.h" #include "board_pins_config.h" #include "esp_peripherals.h" #include "display_service.h" #include "periph_sdcard.h" #ifdef __cplusplus extern "C" { #endif /** * @brief Audio board handle */ struct audio_board_handle { audio_hal_handle_t audio_hal; /*!< audio hardware abstract layer handle */ }; typedef struct audio_board_handle *audio_board_handle_t; /** * @brief Initialize audio board * * @return The audio board handle */ audio_board_handle_t audio_board_init(void); /** * @brief Initialize codec chip * * @return The audio hal handle */ audio_hal_handle_t audio_board_codec_init(void); /** * @brief Initialize led peripheral and display service * * @return The audio display service handle */ display_service_handle_t audio_board_led_init(void); /** * @brief Initialize key peripheral * * @param set The handle of esp_periph_set_handle_t * * @return * - ESP_OK, success * - Others, fail */ esp_err_t audio_board_key_init(esp_periph_set_handle_t set); /** * @brief Initialize sdcard peripheral * * @param set The handle of esp_periph_set_handle_t * * @return * - ESP_OK, success * - Others, fail */ esp_err_t audio_board_sdcard_init(esp_periph_set_handle_t set, periph_sdcard_mode_t mode); /** * @brief Query audio_board_handle * * @return The audio board handle */ audio_board_handle_t audio_board_get_handle(void); /** * @brief Uninitialize the audio board * * @param audio_board The handle of audio board * * @return 0 success, * others fail */ esp_err_t audio_board_deinit(audio_board_handle_t audio_board); #ifdef __cplusplus } #endif #endif
YifuLiu/AliOS-Things
hardware/chip/espressif_adf/esp-adf/components/audio_board/lyrat_v4_3/board.h
C
apache-2.0
2,973
/* * ESPRESSIF MIT License * * Copyright (c) 2019 <ESPRESSIF SYSTEMS (SHANGHAI) CO., LTD> * * Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case, * it is free of charge, to any person obtaining a copy of this software and associated * documentation files (the "Software"), to deal in the Software without restriction, including * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the Software is furnished * to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all copies or * substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * */ #ifndef _AUDIO_BOARD_DEFINITION_H_ #define _AUDIO_BOARD_DEFINITION_H_ #include "driver/touch_pad.h" #define SDCARD_OPEN_FILE_NUM_MAX 5 #define SDCARD_INTR_GPIO GPIO_NUM_34 #define BUTTON_REC_ID GPIO_NUM_36 #define BUTTON_MODE_ID GPIO_NUM_39 #define BUTTON_SET_ID TOUCH_PAD_NUM9 #define BUTTON_PLAY_ID TOUCH_PAD_NUM8 #define BUTTON_VOLUP_ID TOUCH_PAD_NUM7 #define BUTTON_VOLDOWN_ID TOUCH_PAD_NUM4 #define AUXIN_DETECT_GPIO GPIO_NUM_12 #define HEADPHONE_DETECT GPIO_NUM_19 #define PA_ENABLE_GPIO GPIO_NUM_21 #define GREEN_LED_GPIO GPIO_NUM_22 extern audio_hal_func_t AUDIO_CODEC_ES8388_DEFAULT_HANDLE; #define AUDIO_CODEC_DEFAULT_CONFIG(){ \ .adc_input = AUDIO_HAL_ADC_INPUT_LINE1, \ .dac_output = AUDIO_HAL_DAC_OUTPUT_ALL, \ .codec_mode = AUDIO_HAL_CODEC_MODE_BOTH, \ .i2s_iface = { \ .mode = AUDIO_HAL_MODE_SLAVE, \ .fmt = AUDIO_HAL_I2S_NORMAL, \ .samples = AUDIO_HAL_48K_SAMPLES, \ .bits = AUDIO_HAL_BIT_LENGTH_16BITS, \ }, \ }; #define INPUT_KEY_NUM 6 #define INPUT_KEY_DEFAULT_INFO() { \ { \ .type = PERIPH_ID_BUTTON, \ .user_id = INPUT_KEY_USER_ID_REC, \ .act_id = BUTTON_REC_ID, \ }, \ { \ .type = PERIPH_ID_BUTTON, \ .user_id = INPUT_KEY_USER_ID_MODE, \ .act_id = BUTTON_MODE_ID, \ }, \ { \ .type = PERIPH_ID_TOUCH, \ .user_id = INPUT_KEY_USER_ID_SET, \ .act_id = BUTTON_SET_ID, \ }, \ { \ .type = PERIPH_ID_TOUCH, \ .user_id = INPUT_KEY_USER_ID_PLAY, \ .act_id = BUTTON_PLAY_ID, \ }, \ { \ .type = PERIPH_ID_TOUCH, \ .user_id = INPUT_KEY_USER_ID_VOLUP, \ .act_id = BUTTON_VOLUP_ID, \ }, \ { \ .type = PERIPH_ID_TOUCH, \ .user_id = INPUT_KEY_USER_ID_VOLDOWN, \ .act_id = BUTTON_VOLDOWN_ID, \ } \ } #endif
YifuLiu/AliOS-Things
hardware/chip/espressif_adf/esp-adf/components/audio_board/lyrat_v4_3/board_def.h
C
apache-2.0
4,377
/* * ESPRESSIF MIT License * * Copyright (c) 2019 <ESPRESSIF SYSTEMS (SHANGHAI) CO., LTD> * * Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case, * it is free of charge, to any person obtaining a copy of this software and associated * documentation files (the "Software"), to deal in the Software without restriction, including * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the Software is furnished * to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all copies or * substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * */ #include "esp_log.h" #include "driver/gpio.h" #include <string.h> #include "board.h" #include "audio_error.h" #include "audio_mem.h" static const char *TAG = "LYRAT_V4_3"; esp_err_t get_i2c_pins(i2c_port_t port, i2c_config_t *i2c_config) { AUDIO_NULL_CHECK(TAG, i2c_config, return ESP_FAIL); if (port == I2C_NUM_0 || port == I2C_NUM_1) { i2c_config->sda_io_num = GPIO_NUM_18; i2c_config->scl_io_num = GPIO_NUM_23; } else { i2c_config->sda_io_num = -1; i2c_config->scl_io_num = -1; ESP_LOGE(TAG, "i2c port %d is not supported", port); return ESP_FAIL; } return ESP_OK; } esp_err_t get_i2s_pins(i2s_port_t port, i2s_pin_config_t *i2s_config) { AUDIO_NULL_CHECK(TAG, i2s_config, return ESP_FAIL); if (port == I2S_NUM_0 || port == I2S_NUM_1) { i2s_config->bck_io_num = GPIO_NUM_5; i2s_config->ws_io_num = GPIO_NUM_25; i2s_config->data_out_num = GPIO_NUM_26; i2s_config->data_in_num = GPIO_NUM_35; } else { memset(i2s_config, -1, sizeof(i2s_pin_config_t)); ESP_LOGE(TAG, "i2s port %d is not supported", port); return ESP_FAIL; } return ESP_OK; } esp_err_t get_spi_pins(spi_bus_config_t *spi_config, spi_device_interface_config_t *spi_device_interface_config) { AUDIO_NULL_CHECK(TAG, spi_config, return ESP_FAIL); AUDIO_NULL_CHECK(TAG, spi_device_interface_config, return ESP_FAIL); spi_config->mosi_io_num = -1; spi_config->miso_io_num = -1; spi_config->sclk_io_num = -1; spi_config->quadwp_io_num = -1; spi_config->quadhd_io_num = -1; spi_device_interface_config->spics_io_num = -1; ESP_LOGW(TAG, "SPI interface is not supported"); return ESP_OK; } esp_err_t i2s_mclk_gpio_select(i2s_port_t i2s_num, gpio_num_t gpio_num) { if (i2s_num >= I2S_NUM_MAX) { ESP_LOGE(TAG, "Does not support i2s number(%d)", i2s_num); return ESP_ERR_INVALID_ARG; } if (gpio_num != GPIO_NUM_0 && gpio_num != GPIO_NUM_1 && gpio_num != GPIO_NUM_3) { ESP_LOGE(TAG, "Only support GPIO0/GPIO1/GPIO3, gpio_num:%d", gpio_num); return ESP_ERR_INVALID_ARG; } ESP_LOGI(TAG, "I2S%d, MCLK output by GPIO%d", i2s_num, gpio_num); if (i2s_num == I2S_NUM_0) { if (gpio_num == GPIO_NUM_0) { PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO0_U, FUNC_GPIO0_CLK_OUT1); WRITE_PERI_REG(PIN_CTRL, 0xFFF0); } else if (gpio_num == GPIO_NUM_1) { PIN_FUNC_SELECT(PERIPHS_IO_MUX_U0TXD_U, FUNC_U0TXD_CLK_OUT3); WRITE_PERI_REG(PIN_CTRL, 0xF0F0); } else { PIN_FUNC_SELECT(PERIPHS_IO_MUX_U0RXD_U, FUNC_U0RXD_CLK_OUT2); WRITE_PERI_REG(PIN_CTRL, 0xFF00); } } else if (i2s_num == I2S_NUM_1) { if (gpio_num == GPIO_NUM_0) { PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO0_U, FUNC_GPIO0_CLK_OUT1); WRITE_PERI_REG(PIN_CTRL, 0xFFFF); } else if (gpio_num == GPIO_NUM_1) { PIN_FUNC_SELECT(PERIPHS_IO_MUX_U0TXD_U, FUNC_U0TXD_CLK_OUT3); WRITE_PERI_REG(PIN_CTRL, 0xF0FF); } else { PIN_FUNC_SELECT(PERIPHS_IO_MUX_U0RXD_U, FUNC_U0RXD_CLK_OUT2); WRITE_PERI_REG(PIN_CTRL, 0xFF0F); } } return ESP_OK; } // sdcard int8_t get_sdcard_intr_gpio(void) { return SDCARD_INTR_GPIO; } int8_t get_sdcard_open_file_num_max(void) { return SDCARD_OPEN_FILE_NUM_MAX; } // input-output pins int8_t get_auxin_detect_gpio(void) { return AUXIN_DETECT_GPIO; } int8_t get_headphone_detect_gpio(void) { return HEADPHONE_DETECT; } int8_t get_pa_enable_gpio(void) { return PA_ENABLE_GPIO; } // button pins int8_t get_input_rec_id(void) { return BUTTON_REC_ID; } int8_t get_input_mode_id(void) { return BUTTON_MODE_ID; } // touch pins int8_t get_input_set_id(void) { return BUTTON_SET_ID; } int8_t get_input_play_id(void) { return BUTTON_PLAY_ID; } int8_t get_input_volup_id(void) { return BUTTON_VOLUP_ID; } int8_t get_input_voldown_id(void) { return BUTTON_VOLDOWN_ID; } // led pins int8_t get_green_led_gpio(void) { return GREEN_LED_GPIO; }
YifuLiu/AliOS-Things
hardware/chip/espressif_adf/esp-adf/components/audio_board/lyrat_v4_3/board_pins_config.c
C
apache-2.0
5,388
/* * ESPRESSIF MIT License * * Copyright (c) 2019 <ESPRESSIF SYSTEMS (SHANGHAI) CO., LTD> * * Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case, * it is free of charge, to any person obtaining a copy of this software and associated * documentation files (the "Software"), to deal in the Software without restriction, including * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the Software is furnished * to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all copies or * substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * */ #include "esp_log.h" #include "board.h" #include "audio_mem.h" #include "periph_sdcard.h" #include "periph_adc_button.h" #include "led_bar_is31x.h" static const char *TAG = "AUDIO_BOARD"; static audio_board_handle_t board_handle = 0; audio_board_handle_t audio_board_init(void) { if (board_handle) { ESP_LOGW(TAG, "The board has already been initialized!"); return board_handle; } board_handle = (audio_board_handle_t) audio_calloc(1, sizeof(struct audio_board_handle)); AUDIO_MEM_CHECK(TAG, board_handle, return NULL); board_handle->audio_hal = audio_board_codec_init(); return board_handle; } audio_hal_handle_t audio_board_codec_init(void) { audio_hal_codec_config_t audio_codec_cfg = AUDIO_CODEC_DEFAULT_CONFIG(); audio_hal_handle_t codec_hal = audio_hal_init(&audio_codec_cfg, &AUDIO_CODEC_ZL38063_DEFAULT_HANDLE); AUDIO_NULL_CHECK(TAG, codec_hal, return NULL); return codec_hal; } display_service_handle_t audio_board_led_init(void) { esp_periph_handle_t led = led_bar_is31x_init(); AUDIO_NULL_CHECK(TAG, led, return NULL); display_service_config_t display = { .based_cfg = { .task_stack = 0, .task_prio = 0, .task_core = 0, .task_func = NULL, .service_start = NULL, .service_stop = NULL, .service_destroy = NULL, .service_ioctl = led_bar_is31x_pattern, .service_name = "DISPLAY_serv", .user_data = NULL, }, .instance = led, }; return display_service_create(&display); } esp_err_t audio_board_key_init(esp_periph_set_handle_t set) { periph_adc_button_cfg_t adc_btn_cfg = PERIPH_ADC_BUTTON_DEFAULT_CONFIG(); adc_arr_t adc_btn_tag = ADC_DEFAULT_ARR(); adc_btn_cfg.arr = &adc_btn_tag; adc_btn_cfg.arr_size = 1; esp_periph_handle_t adc_btn_handle = periph_adc_button_init(&adc_btn_cfg); AUDIO_NULL_CHECK(TAG, adc_btn_handle, return ESP_ERR_ADF_MEMORY_LACK); return esp_periph_start(set, adc_btn_handle); } esp_err_t audio_board_sdcard_init(esp_periph_set_handle_t set, periph_sdcard_mode_t mode) { if (mode != SD_MODE_1_LINE) { ESP_LOGE(TAG, "current board only support 1-line SD mode!"); return ESP_FAIL; } periph_sdcard_cfg_t sdcard_cfg = { .root = "/sdcard", .card_detect_pin = get_sdcard_intr_gpio(), // GPIO_NUM_34 .mode = mode }; esp_periph_handle_t sdcard_handle = periph_sdcard_init(&sdcard_cfg); esp_err_t ret = esp_periph_start(set, sdcard_handle); int retry_time = 5; bool mount_flag = false; while (retry_time --) { if (periph_sdcard_is_mounted(sdcard_handle)) { mount_flag = true; break; } else { vTaskDelay(500 / portTICK_PERIOD_MS); } } if (mount_flag == false) { ESP_LOGE(TAG, "Sdcard mount failed"); return ESP_FAIL; } return ret; } audio_board_handle_t audio_board_get_handle(void) { return board_handle; } esp_err_t audio_board_deinit(audio_board_handle_t audio_board) { esp_err_t ret = ESP_OK; ret = audio_hal_deinit(audio_board->audio_hal); audio_free(audio_board); board_handle = NULL; return ret; }
YifuLiu/AliOS-Things
hardware/chip/espressif_adf/esp-adf/components/audio_board/lyratd_msc_v2_1/board.c
C
apache-2.0
4,515
/* * ESPRESSIF MIT License * * Copyright (c) 2019 <ESPRESSIF SYSTEMS (SHANGHAI) CO., LTD> * * Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case, * it is free of charge, to any person obtaining a copy of this software and associated * documentation files (the "Software"), to deal in the Software without restriction, including * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the Software is furnished * to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all copies or * substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * */ #ifndef _AUDIO_BOARD_H_ #define _AUDIO_BOARD_H_ #include "audio_hal.h" #include "board_def.h" #include "board_pins_config.h" #include "esp_peripherals.h" #include "display_service.h" #include "periph_sdcard.h" #ifdef __cplusplus extern "C" { #endif /** * @brief Audio board handle */ struct audio_board_handle { audio_hal_handle_t audio_hal; /*!< audio hardware abstract layer handle */ }; typedef struct audio_board_handle *audio_board_handle_t; /** * @brief Initialize audio board * * @return The audio board handle */ audio_board_handle_t audio_board_init(void); /** * @brief Initialize codec chip * * @return The audio hal handle */ audio_hal_handle_t audio_board_codec_init(void); /** * @brief Initialize led peripheral and display service * * @return The audio display service handle */ display_service_handle_t audio_board_led_init(void); /** * @brief Initialize key peripheral * * @param set The handle of esp_periph_set_handle_t * * @return * - ESP_OK, success * - Others, fail */ esp_err_t audio_board_key_init(esp_periph_set_handle_t set); /** * @brief Initialize sdcard peripheral * * @param set The handle of esp_periph_set_handle_t * * @return * - ESP_OK, success * - Others, fail */ esp_err_t audio_board_sdcard_init(esp_periph_set_handle_t set, periph_sdcard_mode_t mode); /** * @brief Query audio_board_handle * * @return The audio board handle */ audio_board_handle_t audio_board_get_handle(void); /** * @brief Uninitialize the audio board * * @param audio_board The handle of audio board * * @return 0 success, * others fail */ esp_err_t audio_board_deinit(audio_board_handle_t audio_board); #ifdef __cplusplus } #endif #endif
YifuLiu/AliOS-Things
hardware/chip/espressif_adf/esp-adf/components/audio_board/lyratd_msc_v2_1/board.h
C
apache-2.0
2,973
/* * ESPRESSIF MIT License * * Copyright (c) 2019 <ESPRESSIF SYSTEMS (SHANGHAI) CO., LTD> * * Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case, * it is free of charge, to any person obtaining a copy of this software and associated * documentation files (the "Software"), to deal in the Software without restriction, including * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the Software is furnished * to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all copies or * substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * */ #ifndef _AUDIO_BOARD_DEFINITION_H_ #define _AUDIO_BOARD_DEFINITION_H_ #define SDCARD_OPEN_FILE_NUM_MAX 5 #define SDCARD_INTR_GPIO GPIO_NUM_34 #define PA_ENABLE_GPIO GPIO_NUM_22 #define ADC_DETECT_GPIO GPIO_NUM_39 #define BUTTON_SET_ID 0 #define BUTTON_PLAY_ID 1 #define BUTTON_REC_ID 2 #define BUTTON_MODE_ID 3 #define BUTTON_VOLDOWN_ID 4 #define BUTTON_VOLUP_ID 5 #define CODEC_RESET_GPIO GPIO_NUM_19 #define DSP_RESET_GPIO GPIO_NUM_21 extern audio_hal_func_t AUDIO_CODEC_ZL38063_DEFAULT_HANDLE; #define AUDIO_CODEC_DEFAULT_CONFIG(){ \ .adc_input = AUDIO_HAL_ADC_INPUT_LINE1, \ .dac_output = AUDIO_HAL_DAC_OUTPUT_ALL, \ .codec_mode = AUDIO_HAL_CODEC_MODE_BOTH, \ .i2s_iface = { \ .mode = AUDIO_HAL_MODE_SLAVE, \ .fmt = AUDIO_HAL_I2S_NORMAL, \ .samples = AUDIO_HAL_48K_SAMPLES, \ .bits = AUDIO_HAL_BIT_LENGTH_16BITS, \ }, \ }; #define INPUT_KEY_NUM 6 #define INPUT_KEY_DEFAULT_INFO() { \ { \ .type = PERIPH_ID_ADC_BTN, \ .user_id = INPUT_KEY_USER_ID_REC, \ .act_id = BUTTON_REC_ID, \ }, \ { \ .type = PERIPH_ID_ADC_BTN, \ .user_id = INPUT_KEY_USER_ID_MODE, \ .act_id = BUTTON_MODE_ID, \ }, \ { \ .type = PERIPH_ID_ADC_BTN, \ .user_id = INPUT_KEY_USER_ID_SET, \ .act_id = BUTTON_SET_ID, \ }, \ { \ .type = PERIPH_ID_ADC_BTN, \ .user_id = INPUT_KEY_USER_ID_PLAY, \ .act_id = BUTTON_PLAY_ID, \ }, \ { \ .type = PERIPH_ID_ADC_BTN, \ .user_id = INPUT_KEY_USER_ID_VOLUP, \ .act_id = BUTTON_VOLUP_ID, \ }, \ { \ .type = PERIPH_ID_ADC_BTN, \ .user_id = INPUT_KEY_USER_ID_VOLDOWN, \ .act_id = BUTTON_VOLDOWN_ID, \ } \ } #endif
YifuLiu/AliOS-Things
hardware/chip/espressif_adf/esp-adf/components/audio_board/lyratd_msc_v2_1/board_def.h
C
apache-2.0
4,152