Cypress-BLE 开发套件可以快速开发 物联网电子产品。
PSOC编程特点:
A 拖放各PSoC 组件到工作区中,以设计原理图
B 完成各组件之间的布线,并配置GPIO
C 使用所包含的组件API 开发和调试固件
一:使用入门:
PSOC Creator :一款 IDE工具,可以直接进行硬件和固件设计,如下图,创建新工程后。我们可以配置电路图,选择需要用的Lib,和设置PSOC。
1. 将组件图标拖放到主要设计工作区中,以进行您的硬件系统设计。
2. 对您的应用固件和PSoC 硬件进行协同设计。
3. 使用配置工具配置各组件
4. 研究包含100 多个组件的库
5. 查看组件数据手册
二:硬件框图
A.>PSOC4 就是PSOC芯片了具体配置查datasheet
B> PSOC5LP是用来配合调试和串口通讯用的 ,还带了很多集成的模数模块,
其他的东西都可以在help文件里面找到。
三:开始项目
扯淡没用,开始项目。
A 原理框图
PSOC的作用就是把很多原来外围电路 配置到IC内部。而Cypress的优势就是把BLE模块集成化,配置蓝牙参数就像填数字,傻瓜操作。
B:Topdesign 顶层设计(就是模块设置咯)
如下图,配置好Pin脚,Uart串口,Ble模块,设置DAC (其他的模块省略)
C 配置引脚
如下图,把需要用到的引脚配置好就行。
D 配置时钟,中断,模拟电路,Flash等,方法同上。
E 写main函数,其他库函数都自动生成了,但功能逻辑函数还是要自己写的,这里编程就和STM32编程一样。
不过PSOC的优势是:所有底层配置都已经ok,只需要加功能性指令。Test功能函数如下,其他函数都是已经配置好了的。
#include "tester.h" #include "tools.h" #include "debug.h" #include "cmd_list.h" #include "hw.h" #include "ble_srv_update.h" #include "ble_srv_list.h" #include "tasks.h" tester_t tester; void tester_init(void){ memset((void*)&tester, 0, sizeof(tester_t)); tester.leds_timeout = 1; } u8 tester_started_get(void){ return tester.started; } void tester_started_set(u8 started){ tester.started = started; // If test is finished - disconnect and delete the mac if(!started){ if(tester.ble_connected){ memset(tester.mac, 0, 6); CyBle_GapDisconnect(cyBle_connHandle.bdHandle); } // Just in case - Reset the processor CySoftwareReset(); tester.update_timeout = 0; tester.board = 0; } tester.key = 0; tester.state = 0; tester.error_timeout = 0; PIN_11_ON; } u8 tester_ble_connected_get(void){ return tester.started; } void tester_ble_connected_set(u8 val){ tester.ble_connected = val; if(!val) { tester.ble_paired = val; tester.update_timeout = 0; // If the 0x0E board is disconnected - reset the tester if((tester.board == 0x0E) && (tester.state == TESTER_STATE_PASSED)){ tester_started_set(0); } DBG_LOG(DEBUG_ACC, " TESTER: BLE Disconnected "); } else { DBG_LOG(DEBUG_ACC, " TESTER: BLE Connected "); } tester.update_timeout = TESTER_UPDATE_TIMEOUT; } void tester_board_set(u8 val){ tester.board = val; // We will write and read the characteristic // on read event - busy will be cleared ble_srv_update(BLE_SU_TEST_MODE); tester.state = 0; } u8 tester_board_get(void){ return tester.board; } void tester_ble_paired_set(u8 val){ if(val){ // Clear busy flag if the cause is waiting for pair if((!tester.ble_paired) && (tester.status & TESTER_FIELD_BUSY)) { tester.status &=~TESTER_FIELD_BUSY; } // Just in case, if disconnection happens, after reconnection // it will go to the test mode if(val && tester.board) { ble_srv_update(BLE_SU_TEST_MODE); } DBG_LOG(DEBUG_ACC, " TESTER: BLE Paired "); } tester.ble_paired = val; tester.error_timeout = 0; } u8 *tester_mac_get(void){ return tester.mac; } void tester_mac_set(u8 *mac){ if(mac == NULL) return; // If test is not started - do not connect if(!tester.started) return; memcpy(tester.mac, mac, 6); } void tester_mac_parse(u8 *data){ u8 sum, sum_rx, i; if(tester.ble_connected) return; if(data == NULL) return; if(data[0] != '<') return; if(data[13]!= '>') return; memset((void*)&tester.mac_tmp[0], 0, sizeof(tester.mac_tmp)); for(i=0, sum=0; i<6; i++){ tester.mac_tmp[5-i] = (ASCII_HEX_TO_DEC(data[1+i*2]) << 4); tester.mac_tmp[5-i]|= ASCII_HEX_TO_DEC(data[2+i*2]); sum += tester.mac_tmp[5-i]; } sum_rx = (ASCII_HEX_TO_DEC(data[14]) << 4); sum_rx|= ASCII_HEX_TO_DEC(data[15]); if(sum != sum_rx) return; tester_mac_set(tester.mac_tmp); } void tester_triac_write(u8 idx, u8 state){ if(state > 1) return; if((idx > 3) || (!idx)) return; tester.idx_triac = idx; if(idx == 1) tester.outputs.triac_1 = state; else if(idx == 2) tester.outputs.triac_2 = state; else if(idx == 3) tester.outputs.triac_3 = state; ble_srv_update(BLE_SU_TRIAC); } void tester_relay_write(u8 idx, u8 state){ if(state > 1) return; if((idx > 3) || (!idx)) return; tester.idx_relay = idx; if(idx == 1) tester.outputs.relay_1 = state; else if(idx == 2) tester.outputs.relay_2 = state; else if(idx == 3) tester.outputs.relay_3 = state; ble_srv_update(BLE_SU_RELAY); } u8 tester_triac_idx_get(void){ return tester.idx_triac; } u8 tester_relay_idx_get(void){ return tester.idx_relay; } u8 tester_triac_state_get(u8 idx){ if(idx == 1) return tester.outputs.triac_1; else if(idx == 2) return tester.outputs.triac_2; else if(idx == 3) return tester.outputs.triac_3; return 0; } u8 tester_relay_state_get(u8 idx){ if(idx == 1) return tester.outputs.relay_1; else if(idx == 2) return tester.outputs.relay_2; else if(idx == 3) return tester.outputs.relay_3; return 0; } void tester_error_set(u8 val){ tester.error = val; } void tester_key_set(u8 val){ if(tester.key != val) tester.timeout = 1; // Speed up on change tester.key = val; } void tester_ntc_set(u8 val){ tester.ntc = val; } void tester_auto_timeout_set(u8 val){ tester.auto_timeout = val; tester.state |= 0x80; tester.error_timeout = 0; } void tester_buzzer_timeout_update(void){ if(tester.buzzer_timeout < 0xFFFF) tester.buzzer_timeout++; } // Tester state machine void tester_10ms_run(void){ // Wrong states - back to initial state if(!tester.started){ // If connected but it not supposed to be connected if(tester.ble_paired){ memset(tester.mac, 0, 6); CyBle_GapDisconnect(cyBle_connHandle.bdHandle); DBG_LOG(DEBUG_ACC, " TESTER: BLE paired - disconnecting "); } else if(tester.ble_connected){ memset(tester.mac, 0, 6); CyBle_GapDisconnect(cyBle_connHandle.bdHandle); DBG_LOG(DEBUG_ACC, " TESTER: BLE connected - disconnecting "); } // Standalone application // Wait till the button will be released if(SW2_STATE){ tester.sw_debaunce = 0; while(SW2_STATE){ CyDelay(10); if(tester.sw_debaunce < 0xFF) tester.sw_debaunce++; } // If the button was pressed more than 60 ms if(tester.sw_debaunce > 6){ // Start EP4114 test DBG_LOG(DEBUG_ACC, " TESTER: EP4114 Test starting... "); tester_started_set(1); tester_board_set(0x0E); } } // Test is started } else { // Check if the error happened if((tester.error_timeout > TESTER_FAIL_TIMEOUT) && (tester.state != TESTER_STATE_FAILED)){ if(tester.ble_paired || (!tester.ble_paired && (tester.error_timeout > TESTER_PAIR_FAIL_TIMEOUT))) { tester.status |= TESTER_FIELD_ERROR; tester.status &=~TESTER_FIELD_BUSY; tester.state = TESTER_STATE_FAILED; DBG_LOG(DEBUG_ACC, " TESTER: FAILED "); tester.error_timeout = 0; } } // If not paired - tell PC that it is busy if(!tester.ble_paired) { tester.status |= TESTER_FIELD_BUSY; tester.error_timeout++; } else { // Busy - all except errors if(ble_srv_update_busy_get()) { if(ble_srv_update_ids_get() &~BLE_SU_ERROR) tester.status |= TESTER_FIELD_BUSY; } else if(tester.board != 0x0E) tester.status &=~TESTER_FIELD_BUSY; if(tester.error || ((tester.board == 0x0E) && (tester.state == TESTER_STATE_FAILED))) tester.status |= TESTER_FIELD_ERROR; else tester.status &=~TESTER_FIELD_ERROR; if(tester.key) tester.status |= TESTER_FIELD_SWITCH; else tester.status &=~TESTER_FIELD_SWITCH; // Zero cross generator for EP4114 if(tester.board == 0x0E){ if(PIN_9_STATE) PIN_9_OFF; else PIN_9_ON; } // EP4114 is automated test if((tester.board == 0x0E) && (!ble_srv_update_busy_get())){ switch(tester.state){ /* ***************************** * Hi / Lo Level test ********************************/ // ********** PIN 2 test ********** // Turn On case TESTER_STATE_PIN2_ON_TURN: tester.status |= TESTER_FIELD_BUSY; tester.outputs.relay_3 = 1; tester.idx_relay = 3; ble_srv_update(BLE_SU_RELAY); tester_auto_timeout_set(TESTER_AUTO_TIMEOUT); break; // On case TESTER_STATE_PIN2_ON_TEST: if(PIN_2_STATE){ tester.state++; DBG_LOG(DEBUG_ACC, " TESTER: PIN2: ON OK "); } else { // Failed if(tester.error_timeout == TESTER_FAIL_TIMEOUT) DBG_LOG(DEBUG_ACC, " TESTER: PIN2: Failed "); tester.error_timeout++; } break; // Turn OFF case TESTER_STATE_PIN2_OFF_TURN: tester.outputs.relay_3 = 0; tester.idx_relay = 3; ble_srv_update(BLE_SU_RELAY); tester_auto_timeout_set(TESTER_AUTO_TIMEOUT); break; // Off case TESTER_STATE_PIN2_OFF_TEST: if(!PIN_2_STATE){ tester.state++; DBG_LOG(DEBUG_ACC, " TESTER: PIN2: OFF OK "); } else { // Failed if(tester.error_timeout == TESTER_FAIL_TIMEOUT) DBG_LOG(DEBUG_ACC, " TESTER: PIN2: Failed "); tester.error_timeout++; } break; // ********** PIN 3 test ********** // Turn On case TESTER_STATE_PIN3_ON_TURN: tester.outputs.triac_1 = 1; tester.idx_triac = 1; ble_srv_update(BLE_SU_TRIAC); tester_auto_timeout_set(TESTER_AUTO_TIMEOUT); break; // On case TESTER_STATE_PIN3_ON_TEST: if(PIN_3_STATE){ tester.state++; DBG_LOG(DEBUG_ACC, " TESTER: PIN3: ON OK "); } else { // Failed if(tester.error_timeout == TESTER_FAIL_TIMEOUT) DBG_LOG(DEBUG_ACC, " TESTER: PIN3: Failed "); tester.error_timeout++; } break; // Turn Off case TESTER_STATE_PIN3_OFF_TURN: tester.outputs.triac_1 = 0; tester.idx_triac = 1; ble_srv_update(BLE_SU_TRIAC); tester_auto_timeout_set(TESTER_AUTO_TIMEOUT); break; // Off case TESTER_STATE_PIN3_OFF_TEST: if(!PIN_3_STATE){ tester.state++; DBG_LOG(DEBUG_ACC, " TESTER: PIN3: OFF OK "); } else { // Failed if(tester.error_timeout == TESTER_FAIL_TIMEOUT) DBG_LOG(DEBUG_ACC, " TESTER: PIN3: Failed "); tester.error_timeout++; } break; // ********** PIN 4 test ********** // Turn On case TESTER_STATE_PIN4_ON_TURN: tester.outputs.triac_2 = 1; tester.idx_triac = 2; ble_srv_update(BLE_SU_TRIAC); tester_auto_timeout_set(TESTER_AUTO_TIMEOUT); break; // On case TESTER_STATE_PIN4_ON_TEST: if(PIN_4_STATE){ tester.state++; DBG_LOG(DEBUG_ACC, " TESTER: PIN4: ON OK "); } else { // Failed if(tester.error_timeout == TESTER_FAIL_TIMEOUT) DBG_LOG(DEBUG_ACC, " TESTER: PIN4: Failed "); tester.error_timeout++; } break; // Turn Off case TESTER_STATE_PIN4_OFF_TURN: tester.outputs.triac_2 = 0; tester.idx_triac = 2; ble_srv_update(BLE_SU_TRIAC); tester_auto_timeout_set(TESTER_AUTO_TIMEOUT); break; // Off case TESTER_STATE_PIN4_OFF_TEST: if(!PIN_4_STATE){ tester.state++; DBG_LOG(DEBUG_ACC, " TESTER: PIN4: OFF OK "); } else { // Failed if(tester.error_timeout == TESTER_FAIL_TIMEOUT) DBG_LOG(DEBUG_ACC, " TESTER: PIN4: Failed "); tester.error_timeout++; } break; // ********** PIN 7 test ********** // Turn On case TESTER_STATE_PIN7_ON_TURN: tester.outputs.relay_1 = 1; tester.idx_relay = 1; ble_srv_update(BLE_SU_RELAY); tester_auto_timeout_set(TESTER_AUTO_TIMEOUT); break; // On case TESTER_STATE_PIN7_ON_TEST: if(PIN_7_STATE){ tester.state++; DBG_LOG(DEBUG_ACC, " TESTER: PIN7: ON OK "); } else { // Failed if(tester.error_timeout == TESTER_FAIL_TIMEOUT) DBG_LOG(DEBUG_ACC, " TESTER: PIN7: Failed "); tester.error_timeout++; } break; // Turn Off case TESTER_STATE_PIN7_OFF_TURN: tester.outputs.relay_1 = 0; tester.idx_relay = 1; ble_srv_update(BLE_SU_RELAY); tester_auto_timeout_set(TESTER_AUTO_TIMEOUT); break; // Off case TESTER_STATE_PIN7_OFF_TEST: if(!PIN_7_STATE){ tester.state++; DBG_LOG(DEBUG_ACC, " TESTER: PIN7: OFF OK "); } else { // Failed if(tester.error_timeout == TESTER_FAIL_TIMEOUT) DBG_LOG(DEBUG_ACC, " TESTER: PIN7: Failed "); tester.error_timeout++; } break; // ********** PIN 8 test ********** // Turn On case TESTER_STATE_PIN8_ON_TURN: tester.outputs.relay_2 = 1; tester.idx_relay = 2; ble_srv_update(BLE_SU_RELAY); tester_auto_timeout_set(TESTER_AUTO_TIMEOUT); break; // On case TESTER_STATE_PIN8_ON_TEST: if(PIN_8_STATE){ tester.state++; DBG_LOG(DEBUG_ACC, " TESTER: PIN8: ON OK "); } else { // Failed if(tester.error_timeout == TESTER_FAIL_TIMEOUT) DBG_LOG(DEBUG_ACC, " TESTER: PIN8: Failed "); tester.error_timeout++; } break; // Turn Off case TESTER_STATE_PIN8_OFF_TURN: tester.outputs.relay_2 = 0; tester.idx_relay = 2; ble_srv_update(BLE_SU_RELAY); tester_auto_timeout_set(TESTER_AUTO_TIMEOUT); break; // Off case TESTER_STATE_PIN8_OFF_TEST: if(!PIN_8_STATE){ tester.state++; DBG_LOG(DEBUG_ACC, " TESTER: PIN8: OFF OK "); } else { // Failed if(tester.error_timeout == TESTER_FAIL_TIMEOUT) DBG_LOG(DEBUG_ACC, " TESTER: PIN8: Failed "); tester.error_timeout++; } break; /* ***************************** * Advance ********************************/ // PIN 5 - ADC case TESTER_STATE_PIN5_TEST: if( ((((info_error_t)tester.error != INFO_ERROR_NTC_ROOM)&& ((info_error_t)tester.error != INFO_ERR_NTC_ROOM)) ) && ((tester.ntc > TESTER_NTC_LIM_MIN) && (tester.ntc < TESTER_NTC_LIM_MAX)) ) { tester.state++; DBG_LOG(DEBUG_ACC, " TESTER: PIN5: OK %u %u ", tester.error, tester.ntc); tester.error_timeout = 0; } else { if(tester.error_timeout == TESTER_FAIL_TIMEOUT) DBG_LOG(DEBUG_ACC, " TESTER: PIN5: Failed %u %u ", tester.error, tester.ntc); tester.error_timeout++; } break; // PIN 9 - Zero cross case TESTER_STATE_PIN9_TEST: if((info_error_t)tester.error != INFO_ERR_ZERO_CROSS){ tester.state++; DBG_LOG(DEBUG_ACC, " TESTER: PIN9: OK %u ", tester.error); tester.error_timeout = 0; } else { if(tester.error_timeout == TESTER_FAIL_TIMEOUT) DBG_LOG(DEBUG_ACC, " TESTER: PIN9: Failed %u ", tester.error); tester.error_timeout++; } tester.buzzer_timeout = 0; break; // PIN 10 - Buzzer // Low case TESTER_STATE_PIN10_OFF_TEST: if(tester.buzzer_timeout < 3000){ while(PIN_10_STATE){ tasks_run_critical(); if(tester.buzzer_timeout > 3000) break; } if(tester.buzzer_timeout < 3000){ DBG_LOG(DEBUG_ACC, " TESTER: PIN10: OFF OK "); tester.state++; tester.buzzer_timeout = 0; tester.error_timeout = 0; } } else { if(tester.error_timeout == TESTER_FAIL_TIMEOUT) DBG_LOG(DEBUG_ACC, " TESTER: PIN10: Failed "); tester.error_timeout++; } break; // High case TESTER_STATE_PIN10_ON_TEST: if(tester.buzzer_timeout < 3000){ while(!PIN_10_STATE){ tasks_run_critical(); if(tester.buzzer_timeout > 3000) break; } if(tester.buzzer_timeout < 3000){ DBG_LOG(DEBUG_ACC, " TESTER: PIN10: ON OK "); tester.state++; tester.buzzer_timeout = 0; tester.error_timeout = 0; } } else { if(tester.error_timeout == TESTER_FAIL_TIMEOUT) DBG_LOG(DEBUG_ACC, " TESTER: PIN10: Failed "); tester.error_timeout++; } break; // PIN 11 - Switch // Turn Off case TESTER_STATE_PIN11_OFF_TURN: PIN_11_ON; tester_auto_timeout_set(TESTER_AUTO_SW_TIMEOUT); break; // Read the state case TESTER_STATE_PIN11_OFF_READ: ble_srv_update(BLE_SU_ERROR); tester_auto_timeout_set(TESTER_AUTO_TIMEOUT); break; // Off case TESTER_STATE_PIN11_OFF_TEST: if(tester.key == 0){ tester.state++; DBG_LOG(DEBUG_ACC, " TESTER: PIN11: OFF OK "); tester.error_timeout = 0; } else { if(tester.error_timeout == TESTER_FAIL_TIMEOUT) DBG_LOG(DEBUG_ACC, " TESTER: PIN11: Failed "); tester.error_timeout++; } break; // Turn On case TESTER_STATE_PIN11_ON_TURN: PIN_11_OFF; tester_auto_timeout_set(TESTER_AUTO_SW_TIMEOUT); break; // Read case TESTER_STATE_PIN11_ON_READ: ble_srv_update(BLE_SU_ERROR); tester_auto_timeout_set(TESTER_AUTO_TIMEOUT); break; // On case TESTER_STATE_PIN11_ON_TEST: if(tester.key){ tester.state++; DBG_LOG(DEBUG_ACC, " TESTER: PIN11: ON OK "); tester.error_timeout = 0; PIN_11_ON; } else { if(tester.error_timeout == TESTER_FAIL_TIMEOUT) DBG_LOG(DEBUG_ACC, " TESTER: PIN11: Failed "); tester.error_timeout++; } break; case TESTER_STATE_CLEAR_BUSY: tester.status &=~TESTER_FIELD_BUSY; DBG_LOG(DEBUG_ACC, " TESTER: PASSED "); tester.state++; tester.error_timeout = 0; break; case TESTER_STATE_PASSED: case TESTER_STATE_FAILED: // Stay here break; case (TESTER_STATE_PIN2_ON_TURN|0x80): case (TESTER_STATE_PIN2_OFF_TURN|0x80): case (TESTER_STATE_PIN3_ON_TURN|0x80): case (TESTER_STATE_PIN3_OFF_TURN|0x80): case (TESTER_STATE_PIN4_ON_TURN|0x80): case (TESTER_STATE_PIN4_OFF_TURN|0x80): case (TESTER_STATE_PIN7_ON_TURN|0x80): case (TESTER_STATE_PIN7_OFF_TURN|0x80): case (TESTER_STATE_PIN8_ON_TURN|0x80): case (TESTER_STATE_PIN8_OFF_TURN|0x80): case (TESTER_STATE_PIN11_OFF_TURN|0x80): case (TESTER_STATE_PIN11_OFF_READ|0x80): case (TESTER_STATE_PIN11_ON_TURN|0x80): case (TESTER_STATE_PIN11_ON_READ|0x80): if(tester.auto_timeout){ if(!(--tester.auto_timeout)){ tester.state = (tester.state & 0x7F) + 1; } } break; default: tester.state = 0; break; } } } } // Tester board to PC UART wirte handling if(tester.timeout) { if(!(--tester.timeout)){ // Send that the error or busy no longer exists if(!(tester.status & (TESTER_FIELD_ERROR | TESTER_FIELD_BUSY))) cmd_status(tester.status, tester.mac); } } else { // If error - send it up to the PC if(tester.status & (TESTER_FIELD_ERROR | TESTER_FIELD_BUSY)) { cmd_status(tester.status, tester.mac); tester.timeout = TESTER_UART_TIMEOUT; } } // Error update from the BLE if(tester.update_timeout) { if(!(--tester.update_timeout)){ if(tester.ble_paired) ble_srv_list_read_add(BLE_SRV_LIST_TEST); tester.update_timeout = TESTER_UPDATE_TIMEOUT; // If no comunication is on going send the status packet if(!tester.timeout){ //cmd_status(tester.status, tester.mac); // ? } } } // Board LEDs handling if(tester.started){ // Blue if(tester.ble_paired){ if(tester.board == 0x0E){ switch(tester.state){ case TESTER_STATE_PASSED: case TESTER_STATE_CLEAR_BUSY: LED_RED_OFF; LED_GREEN_ON; LED_BLUE_OFF; break; case TESTER_STATE_PIN2_ON_TEST: case TESTER_STATE_PIN2_OFF_TEST: case TESTER_STATE_PIN3_ON_TEST: case TESTER_STATE_PIN3_OFF_TEST: case TESTER_STATE_PIN4_ON_TEST: case TESTER_STATE_PIN4_OFF_TEST: case TESTER_STATE_PIN7_ON_TEST: case TESTER_STATE_PIN7_OFF_TEST: case TESTER_STATE_PIN8_ON_TEST: case TESTER_STATE_PIN8_OFF_TEST: case TESTER_STATE_PIN5_TEST: case TESTER_STATE_PIN9_TEST: case TESTER_STATE_PIN11_OFF_TEST: case TESTER_STATE_PIN11_ON_TEST: case TESTER_STATE_PIN10_OFF_TEST: case TESTER_STATE_PIN10_ON_TEST: LED_RED_ON; LED_GREEN_OFF; LED_BLUE_ON; break; case (TESTER_STATE_PIN2_ON_TURN): case (TESTER_STATE_PIN2_OFF_TURN): case (TESTER_STATE_PIN3_ON_TURN): case (TESTER_STATE_PIN3_OFF_TURN): case (TESTER_STATE_PIN4_ON_TURN): case (TESTER_STATE_PIN4_OFF_TURN): case (TESTER_STATE_PIN7_ON_TURN): case (TESTER_STATE_PIN7_OFF_TURN): case (TESTER_STATE_PIN8_ON_TURN): case (TESTER_STATE_PIN8_OFF_TURN): case (TESTER_STATE_PIN11_OFF_TURN): case (TESTER_STATE_PIN11_OFF_READ): case (TESTER_STATE_PIN11_ON_TURN): case (TESTER_STATE_PIN11_ON_READ): case (TESTER_STATE_PIN2_ON_TURN|0x80): case (TESTER_STATE_PIN2_OFF_TURN|0x80): case (TESTER_STATE_PIN3_ON_TURN|0x80): case (TESTER_STATE_PIN3_OFF_TURN|0x80): case (TESTER_STATE_PIN4_ON_TURN|0x80): case (TESTER_STATE_PIN4_OFF_TURN|0x80): case (TESTER_STATE_PIN7_ON_TURN|0x80): case (TESTER_STATE_PIN7_OFF_TURN|0x80): case (TESTER_STATE_PIN8_ON_TURN|0x80): case (TESTER_STATE_PIN8_OFF_TURN|0x80): case (TESTER_STATE_PIN11_OFF_TURN|0x80): case (TESTER_STATE_PIN11_OFF_READ|0x80): case (TESTER_STATE_PIN11_ON_TURN|0x80): case (TESTER_STATE_PIN11_ON_READ|0x80): LED_RED_OFF; LED_GREEN_OFF; LED_BLUE_ON; break; case TESTER_STATE_FAILED: default: LED_RED_ON; LED_GREEN_OFF; LED_BLUE_OFF; break; } } else { LED_RED_OFF; LED_GREEN_OFF; LED_BLUE_ON; } // Blue Flashing slow } else if(tester.ble_connected){ if(tester.leds_timeout){ if(!(--tester.leds_timeout)){ tester.leds_timeout = TESTER_LEDS_SLOW_TIMEOUT; if(LED_BLUE_STATE){ LED_RED_OFF; LED_GREEN_OFF; LED_BLUE_OFF; } else { LED_RED_OFF; LED_GREEN_OFF; LED_BLUE_ON; } } } // Blue Flashing fast } else { if(tester.state == TESTER_STATE_FAILED){ LED_RED_ON; LED_GREEN_OFF; LED_BLUE_OFF; } else { if(tester.leds_timeout){ if(!(--tester.leds_timeout)){ tester.leds_timeout = TESTER_LEDS_FAST_TIMEOUT; if(LED_BLUE_STATE){ LED_RED_OFF; LED_GREEN_OFF; LED_BLUE_OFF; } else { LED_RED_OFF; LED_GREEN_OFF; LED_BLUE_ON; } } } } } // Red } else { if(tester.leds_timeout){ if(!(--tester.leds_timeout)){ tester.leds_timeout = TESTER_LEDS_TIMEOUT; if(LED_RED_STATE){ LED_RED_OFF; LED_GREEN_OFF; LED_BLUE_OFF; } else { LED_RED_ON; LED_GREEN_OFF; LED_BLUE_OFF; } } } } }
四:调试
这里只测试了BLE输出电平逻辑,LCD ,KEY, Cap sense 等在另一板子上。
4总结