This commit is contained in:
YiChin
2019-07-18 16:28:50 +08:00
parent dbe5257f3a
commit d8ac537fba
4 changed files with 70 additions and 73 deletions
@@ -34,7 +34,7 @@ static SPI_Transaction ADC_DAC_transaction;
static void Elite_SPI_init(){
SPI_init();
SPI_Params_init(&spiParams0);
spiParams0.bitRate = 12000; // 12k
spiParams0.bitRate = 500; // 12k
spiParams0.mode = SPI_MASTER;
spiParams0.dataSize = 16;
spiParams0.frameFormat = SPI_POL0_PHA1;
@@ -460,9 +460,6 @@ static bool DACreset = true;
#define BLE_DAT_BUFF_SIZE SIMPLEPROFILE_CHAR4_LEN
//#endif
#define DARKLED 0xEF
#define LIGHTLED 0xF4
/**
* application use instruction receive buffer.
* the length equals to the characteristic 3 which value is 12 bytes.
@@ -612,8 +609,6 @@ static int32_t DecodeADCVolt(uint8_t ADCin);
static void EliteKeyPress(uint8_t key);
static bool TurnOnElite(uint8_t key);
static void LED_color(uint8_t bright, uint8_t red, uint8_t green, uint8_t blue);
#define LEDPowerON() LED_color(DARKLED, 0x00, 0xFA, 0x00)
static void WorkModeLED();
static void KeyWorkModeLED();
@@ -77,8 +77,8 @@ static void ZM_init() {
// initialize
pin_handle = PIN_open(&ZM_rst, BLE_IO);
PIN_setOutputValue(pin_handle, shutdown_6994, 0); // OFF = 1 => turn off 6994
// PIN_setOutputValue(pin_handle, enable_10v, 1); // enable 10V
PIN_setOutputValue(pin_handle, shutdown_6994, 1); // OFF = 1 => turn off 6994
PIN_setOutputValue(pin_handle, enable_10v, 0); // enable 10V
PIN_setOutputValue(pin_handle, ADC_CS, 1); // ADC_CS HIGH
PIN_setOutputValue(pin_handle, DAC_CS, 1); // DAC_CS HIGH
@@ -87,6 +87,11 @@ static void ZM_init() {
// PIN_setInterrupt(pin_handle, switch_on | PIN_IRQ_POSEDGE);
}
#define DARKLED 0xE1
#define LIGHTLED 0xE8
static void LED_color(uint8_t bright, uint8_t red, uint8_t green, uint8_t blue);
#define LEDPowerON() LED_color(DARKLED, 0x00, 0xFA, 0x00)
static void LTC_6994_init() {
LED_color(0xf0,0x00, 0x00, 0xff);
CPUdelay(0x03FFFFFF); // 0.5 sec
@@ -781,6 +786,64 @@ static void KeyWorkModeLED(){
}
}
static void CleanBuffer(){
PeriodicEvent = false;
VoltOrigin = DACzero;
VoltFinal = DACposMax;
Step = 10; // 10 = 0x0A ~= 3.05 mv ~= 3 mv
StepTime = 24; // 0x30 = 2'd48 ~= 2 second, 24 = 0x18
PeriodicCounter = 0;
for(int i=0 ; i<SPI_LED_SIZE ; i++){
spi_LEDtxbuf[i] = 0;
spi_LEDrxbuf[i] = 0;
}
for(int i=0 ; i<SPI_DAC_SIZE ; i++){
spi_DACtxbuf[i] = 0;
spi_rxbuf[i] = 0;
}
for(int i=0 ; i<SPI_ADC_SIZE ; i++){
spi_ADC_txbuf[i] = 0;
spi_ADC_rxbuf[i] = 0;
}
for(int i=0 ; i<BLE_DAT_BUFF_SIZE ; i++){
not_buf[i] = 0;
}
SPI_close(spiHandle0); //
Elite_SPI_init();
PIN_setOutputValue(pin_handle, ADC_CS, 1); // ADC_CS HIGH
PIN_setOutputValue(pin_handle, DAC_CS, 1); // DAC_CS HIGH
CPUdelay(8000);
}
static bool TurnOnElite(uint8_t key){
static uint8_t TurnOnCounter = 0;
if(key == 0){
// press 1 sec, power on LED
if(TurnOnCounter >= 15){
PIN_setOutputValue(pin_handle, enable_5v, 1); // enable 5V
// TurnOn10V();
LEDPowerON();
return true;
}
else{
TurnOnCounter ++;
return false;
}
}
else{
TurnOnCounter = 0;
PIN_setOutputValue(pin_handle, enable_5v, 0); // enable 5V
return false;
}
}
static void EliteKeyPress(uint8_t key){
static uint8_t ShutDownCounter = 0;
static uint8_t OriginEliteFxn = 0;
@@ -818,64 +881,6 @@ static void EliteKeyPress(uint8_t key){
}
}
static bool TurnOnElite(uint8_t key){
static uint8_t TurnOnCounter = 0;
if(key == 0){
// press 1 sec, power on LED
if(TurnOnCounter >= 15){
PIN_setOutputValue(pin_handle, enable_5v, 1); // enable 5V
// TurnOn10V();
LEDPowerON();
return true;
}
else{
TurnOnCounter ++;
return false;
}
}
else{
TurnOnCounter = 0;
PIN_setOutputValue(pin_handle, enable_5v, 0); // enable 5V
return false;
}
}
static void CleanBuffer(){
PeriodicEvent = false;
VoltOrigin = DACzero;
VoltFinal = DACposMax;
Step = 10; // 10 = 0x0A ~= 3.05 mv ~= 3 mv
StepTime = 24; // 0x30 = 2'd48 ~= 2 second, 24 = 0x18
PeriodicCounter = 0;
for(int i=0 ; i<SPI_LED_SIZE ; i++){
spi_LEDtxbuf[i] = 0;
spi_LEDrxbuf[i] = 0;
}
for(int i=0 ; i<SPI_DAC_SIZE ; i++){
spi_DACtxbuf[i] = 0;
spi_rxbuf[i] = 0;
}
for(int i=0 ; i<SPI_ADC_SIZE ; i++){
spi_ADC_txbuf[i] = 0;
spi_ADC_rxbuf[i] = 0;
}
for(int i=0 ; i<BLE_DAT_BUFF_SIZE ; i++){
not_buf[i] = 0;
}
SPI_close(spiHandle0); //
Elite_SPI_init();
PIN_setOutputValue(pin_handle, ADC_CS, 1); // ADC_CS HIGH
PIN_setOutputValue(pin_handle, DAC_CS, 1); // DAC_CS HIGH
CPUdelay(8000);
}
static void reset(){
PeriodicEvent = false;
VoltOrigin = DACzero;
@@ -556,19 +556,16 @@ static void SimpleBLEPeripheral_taskFxn(UArg a0, UArg a1) {
// I2Cinit();
// LEDPowerON();
PIN_setOutputValue(pin_handle, enable_10v, 0);
uint8_t key = 0;
uint8_t counter6994 = 0;
bool EliteOn = 0;
// Util_constructClock(&periodicClock, SimpleBLEPeripheral_clockHandler, SBP_PERIODIC_EVT_PERIOD, 0, false, SBP_PERIODIC_EVT);
// Util_startClock(&periodicClock);
Util_constructClock(&periodicClock, SimpleBLEPeripheral_clockHandler, SBP_PERIODIC_EVT_PERIOD, 0, false, SBP_PERIODIC_EVT);
Util_startClock(&periodicClock);
// Application main loops
for (;;) {
// LED_color(DARKLED, 0x0A, 0x00, 0x00);
// Waits for a signal to the semaphore associated with the calling thread.
// Note that the semaphore associated with a thread is signaled when a
// message is queued to the message receive queue of the thread or when
@@ -616,8 +613,8 @@ static void SimpleBLEPeripheral_taskFxn(UArg a0, UArg a1) {
}
}
if(!PeriodicEvent){
// LED_color(DARKLED, 0x00, 0x0A, 0x0A);
Util_startClock(&periodicClock);
key = PIN_getInputValue(switch_on);
if(EliteOn){