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, , sizeof(tester_t));
tester.leds_timeout = ;
} 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, , );
CyBle_GapDisconnect(cyBle_connHandle.bdHandle);
}
// Just in case - Reset the processor
CySoftwareReset(); tester.update_timeout = ;
tester.board = ;
}
tester.key = ;
tester.state = ;
tester.error_timeout = ;
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 = ; // If the 0x0E board is disconnected - reset the tester
if((tester.board == 0x0E) && (tester.state == TESTER_STATE_PASSED)){
tester_started_set();
}
DBG_LOG(DEBUG_ACC, "\n\rTESTER: BLE Disconnected ");
} else {
DBG_LOG(DEBUG_ACC, "\n\rTESTER: 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 = ;
} 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, "\n\rTESTER: BLE Paired ");
}
tester.ble_paired = val;
tester.error_timeout = ;
} 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, );
} void tester_mac_parse(u8 *data){
u8 sum, sum_rx, i;
if(tester.ble_connected) return;
if(data == NULL) return;
if(data[] != '<') return;
if(data[]!= '>') return; memset((void*)&tester.mac_tmp[], , sizeof(tester.mac_tmp)); for(i=, sum=; i<; i++){
tester.mac_tmp[-i] = (ASCII_HEX_TO_DEC(data[+i*]) << );
tester.mac_tmp[-i]|= ASCII_HEX_TO_DEC(data[+i*]);
sum += tester.mac_tmp[-i];
} sum_rx = (ASCII_HEX_TO_DEC(data[]) << );
sum_rx|= ASCII_HEX_TO_DEC(data[]); if(sum != sum_rx) return; tester_mac_set(tester.mac_tmp);
} void tester_triac_write(u8 idx, u8 state){
if(state > ) return;
if((idx > ) || (!idx)) return; tester.idx_triac = idx;
if(idx == ) tester.outputs.triac_1 = state;
else if(idx == ) tester.outputs.triac_2 = state;
else if(idx == ) tester.outputs.triac_3 = state;
ble_srv_update(BLE_SU_TRIAC);
} void tester_relay_write(u8 idx, u8 state){
if(state > ) return;
if((idx > ) || (!idx)) return; tester.idx_relay = idx;
if(idx == ) tester.outputs.relay_1 = state;
else if(idx == ) tester.outputs.relay_2 = state;
else if(idx == ) 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 == ) return tester.outputs.triac_1;
else if(idx == ) return tester.outputs.triac_2;
else if(idx == ) return tester.outputs.triac_3;
return ;
} u8 tester_relay_state_get(u8 idx){
if(idx == ) return tester.outputs.relay_1;
else if(idx == ) return tester.outputs.relay_2;
else if(idx == ) return tester.outputs.relay_3;
return ;
} void tester_error_set(u8 val){
tester.error = val;
} void tester_key_set(u8 val){
if(tester.key != val) tester.timeout = ; // 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 = ;
} 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, , );
CyBle_GapDisconnect(cyBle_connHandle.bdHandle);
DBG_LOG(DEBUG_ACC, "\n\rTESTER: BLE paired - disconnecting ");
} else if(tester.ble_connected){
memset(tester.mac, , );
CyBle_GapDisconnect(cyBle_connHandle.bdHandle);
DBG_LOG(DEBUG_ACC, "\n\rTESTER: BLE connected - disconnecting ");
} // Standalone application
// Wait till the button will be released
if(SW2_STATE){
tester.sw_debaunce = ;
while(SW2_STATE){
CyDelay();
if(tester.sw_debaunce < 0xFF) tester.sw_debaunce++;
}
// If the button was pressed more than 60 ms
if(tester.sw_debaunce > ){
// Start EP4114 test
DBG_LOG(DEBUG_ACC, "\n\rTESTER: EP4114 Test starting... ");
tester_started_set();
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, "\n\rTESTER: FAILED ");
tester.error_timeout = ;
}
} // 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 = ;
tester.idx_relay = ;
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, "\n\rTESTER: PIN2: ON OK ");
} else {
// Failed
if(tester.error_timeout == TESTER_FAIL_TIMEOUT)
DBG_LOG(DEBUG_ACC, "\n\rTESTER: PIN2: Failed ");
tester.error_timeout++;
}
break;
// Turn OFF
case TESTER_STATE_PIN2_OFF_TURN:
tester.outputs.relay_3 = ;
tester.idx_relay = ;
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, "\n\rTESTER: PIN2: OFF OK ");
} else {
// Failed
if(tester.error_timeout == TESTER_FAIL_TIMEOUT)
DBG_LOG(DEBUG_ACC, "\n\rTESTER: PIN2: Failed ");
tester.error_timeout++;
}
break; // ********** PIN 3 test **********
// Turn On
case TESTER_STATE_PIN3_ON_TURN:
tester.outputs.triac_1 = ;
tester.idx_triac = ;
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, "\n\rTESTER: PIN3: ON OK ");
} else {
// Failed
if(tester.error_timeout == TESTER_FAIL_TIMEOUT)
DBG_LOG(DEBUG_ACC, "\n\rTESTER: PIN3: Failed ");
tester.error_timeout++;
}
break;
// Turn Off
case TESTER_STATE_PIN3_OFF_TURN:
tester.outputs.triac_1 = ;
tester.idx_triac = ;
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, "\n\rTESTER: PIN3: OFF OK ");
} else {
// Failed
if(tester.error_timeout == TESTER_FAIL_TIMEOUT)
DBG_LOG(DEBUG_ACC, "\n\rTESTER: PIN3: Failed ");
tester.error_timeout++;
}
break; // ********** PIN 4 test **********
// Turn On
case TESTER_STATE_PIN4_ON_TURN:
tester.outputs.triac_2 = ;
tester.idx_triac = ;
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, "\n\rTESTER: PIN4: ON OK ");
} else {
// Failed
if(tester.error_timeout == TESTER_FAIL_TIMEOUT)
DBG_LOG(DEBUG_ACC, "\n\rTESTER: PIN4: Failed ");
tester.error_timeout++;
}
break;
// Turn Off
case TESTER_STATE_PIN4_OFF_TURN:
tester.outputs.triac_2 = ;
tester.idx_triac = ;
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, "\n\rTESTER: PIN4: OFF OK ");
} else {
// Failed
if(tester.error_timeout == TESTER_FAIL_TIMEOUT)
DBG_LOG(DEBUG_ACC, "\n\rTESTER: PIN4: Failed ");
tester.error_timeout++;
}
break; // ********** PIN 7 test **********
// Turn On
case TESTER_STATE_PIN7_ON_TURN:
tester.outputs.relay_1 = ;
tester.idx_relay = ;
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, "\n\rTESTER: PIN7: ON OK ");
} else {
// Failed
if(tester.error_timeout == TESTER_FAIL_TIMEOUT)
DBG_LOG(DEBUG_ACC, "\n\rTESTER: PIN7: Failed ");
tester.error_timeout++;
}
break;
// Turn Off
case TESTER_STATE_PIN7_OFF_TURN:
tester.outputs.relay_1 = ;
tester.idx_relay = ;
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, "\n\rTESTER: PIN7: OFF OK ");
} else {
// Failed
if(tester.error_timeout == TESTER_FAIL_TIMEOUT)
DBG_LOG(DEBUG_ACC, "\n\rTESTER: PIN7: Failed ");
tester.error_timeout++;
}
break;
// ********** PIN 8 test **********
// Turn On
case TESTER_STATE_PIN8_ON_TURN:
tester.outputs.relay_2 = ;
tester.idx_relay = ;
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, "\n\rTESTER: PIN8: ON OK ");
} else {
// Failed
if(tester.error_timeout == TESTER_FAIL_TIMEOUT)
DBG_LOG(DEBUG_ACC, "\n\rTESTER: PIN8: Failed ");
tester.error_timeout++;
}
break;
// Turn Off
case TESTER_STATE_PIN8_OFF_TURN:
tester.outputs.relay_2 = ;
tester.idx_relay = ;
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, "\n\rTESTER: PIN8: OFF OK ");
} else {
// Failed
if(tester.error_timeout == TESTER_FAIL_TIMEOUT)
DBG_LOG(DEBUG_ACC, "\n\rTESTER: 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, "\n\rTESTER: PIN5: OK %u %u ", tester.error, tester.ntc);
tester.error_timeout = ;
} else {
if(tester.error_timeout == TESTER_FAIL_TIMEOUT)
DBG_LOG(DEBUG_ACC, "\n\rTESTER: 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, "\n\rTESTER: PIN9: OK %u ", tester.error);
tester.error_timeout = ;
} else {
if(tester.error_timeout == TESTER_FAIL_TIMEOUT)
DBG_LOG(DEBUG_ACC, "\n\rTESTER: PIN9: Failed %u ", tester.error);
tester.error_timeout++;
}
tester.buzzer_timeout = ;
break; // PIN 10 - Buzzer
// Low
case TESTER_STATE_PIN10_OFF_TEST:
if(tester.buzzer_timeout < ){
while(PIN_10_STATE){
tasks_run_critical();
if(tester.buzzer_timeout > ) break;
}
if(tester.buzzer_timeout < ){
DBG_LOG(DEBUG_ACC, "\n\rTESTER: PIN10: OFF OK ");
tester.state++;
tester.buzzer_timeout = ;
tester.error_timeout = ;
}
} else {
if(tester.error_timeout == TESTER_FAIL_TIMEOUT)
DBG_LOG(DEBUG_ACC, "\n\rTESTER: PIN10: Failed ");
tester.error_timeout++;
}
break;
// High
case TESTER_STATE_PIN10_ON_TEST:
if(tester.buzzer_timeout < ){
while(!PIN_10_STATE){
tasks_run_critical();
if(tester.buzzer_timeout > ) break;
}
if(tester.buzzer_timeout < ){
DBG_LOG(DEBUG_ACC, "\n\rTESTER: PIN10: ON OK ");
tester.state++;
tester.buzzer_timeout = ;
tester.error_timeout = ;
}
} else {
if(tester.error_timeout == TESTER_FAIL_TIMEOUT)
DBG_LOG(DEBUG_ACC, "\n\rTESTER: 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 == ){
tester.state++;
DBG_LOG(DEBUG_ACC, "\n\rTESTER: PIN11: OFF OK ");
tester.error_timeout = ;
} else {
if(tester.error_timeout == TESTER_FAIL_TIMEOUT)
DBG_LOG(DEBUG_ACC, "\n\rTESTER: 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, "\n\rTESTER: PIN11: ON OK ");
tester.error_timeout = ;
PIN_11_ON;
} else {
if(tester.error_timeout == TESTER_FAIL_TIMEOUT)
DBG_LOG(DEBUG_ACC, "\n\rTESTER: PIN11: Failed ");
tester.error_timeout++;
}
break; case TESTER_STATE_CLEAR_BUSY:
tester.status &=~TESTER_FIELD_BUSY;
DBG_LOG(DEBUG_ACC, "\n\rTESTER: PASSED ");
tester.state++;
tester.error_timeout = ;
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) + ;
}
}
break; default:
tester.state = ;
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总结