Compare commits
16 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 315ec96c11 | |||
| 5d51463dcc | |||
| a60db5d68b | |||
| e70e3141a1 | |||
| 50587152b0 | |||
| ae9a96dfbb | |||
| 0f351b5846 | |||
| 7955927697 | |||
| 7745b6c71f | |||
| 607ccb6e27 | |||
| 1cd1ccabb8 | |||
| d5f2d03279 | |||
| 579d7bc4e8 | |||
| 0f200bddfa | |||
| fd58c97730 | |||
| 77c18b87d9 |
|
After Width: | Height: | Size: 144 KiB |
|
After Width: | Height: | Size: 128 KiB |
|
After Width: | Height: | Size: 152 KiB |
|
After Width: | Height: | Size: 173 KiB |
|
After Width: | Height: | Size: 203 KiB |
|
After Width: | Height: | Size: 149 KiB |
|
After Width: | Height: | Size: 127 KiB |
|
After Width: | Height: | Size: 112 KiB |
|
After Width: | Height: | Size: 174 KiB |
|
After Width: | Height: | Size: 208 KiB |
|
After Width: | Height: | Size: 155 KiB |
|
After Width: | Height: | Size: 133 KiB |
|
After Width: | Height: | Size: 154 KiB |
|
After Width: | Height: | Size: 171 KiB |
|
After Width: | Height: | Size: 212 KiB |
|
After Width: | Height: | Size: 152 KiB |
|
After Width: | Height: | Size: 135 KiB |
|
After Width: | Height: | Size: 107 KiB |
|
After Width: | Height: | Size: 169 KiB |
|
After Width: | Height: | Size: 203 KiB |
|
Before Width: | Height: | Size: 48 KiB |
|
Before Width: | Height: | Size: 166 KiB |
@@ -50,7 +50,7 @@ extern "C" {
|
||||
* ==========================================================================*/
|
||||
#include <ti/drivers/PIN.h>
|
||||
#include <driverlib/ioc.h>
|
||||
#include "application_config/application_config.h"
|
||||
#include "app_config.h"
|
||||
|
||||
/** ============================================================================
|
||||
* Externs
|
||||
@@ -166,6 +166,7 @@ extern const PIN_Config BoardGpioInitTable[];
|
||||
#define Board_SPI0_MOSI Board_BP_SPI_MOSI
|
||||
#define Board_SPI0_CLK Board_BP_SPI_CLK
|
||||
#define Board_SPI0_CS Board_BP_SPI_CS_Wireless
|
||||
#error "DEF_ELITE_MODEL not defined"
|
||||
#else
|
||||
#define Board_SPI0_MISO E_SPI0_MISO
|
||||
#define Board_SPI0_MOSI E_SPI0_MOSI
|
||||
|
||||
@@ -0,0 +1,147 @@
|
||||
#include <stdint.h>
|
||||
#include "app_config.h"
|
||||
|
||||
#if(!CC2650_CODE)
|
||||
#include "nrf_log.h"
|
||||
#include "nrf_log_ctrl.h"
|
||||
#include "nrf_log_default_backends.h"
|
||||
#endif
|
||||
|
||||
#define ADG1408_S1 0
|
||||
#define ADG1408_S2 1
|
||||
#define ADG1408_S3 2
|
||||
#define ADG1408_S4 3
|
||||
#define ADG1408_S5 4
|
||||
#define ADG1408_S6 5
|
||||
#define ADG1408_S7 6
|
||||
#define ADG1408_S8 7
|
||||
|
||||
struct ADG1408_pin_t {
|
||||
bool A0;
|
||||
bool A1;
|
||||
bool A2;
|
||||
};
|
||||
|
||||
extern void set_pin_ADCA0(bool boolflag);
|
||||
extern void set_pin_ADCA1(bool boolflag);
|
||||
extern void set_pin_ADCA2(bool boolflag);
|
||||
static void ADG1408_output(struct ADG1408_pin_t *adc_sel)
|
||||
{
|
||||
set_pin_ADCA0(adc_sel->A0);
|
||||
set_pin_ADCA1(adc_sel->A1);
|
||||
set_pin_ADCA2(adc_sel->A2);
|
||||
#if(!CC2650_CODE)
|
||||
NRF_LOG_INFO("ADC selector [A2,A1,A0]: %d%d%d", adc_sel->A2, adc_sel->A1, adc_sel->A0);
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
* +----+----------+
|
||||
* | | A2 A1 A0 |
|
||||
* +----+----------+
|
||||
* | S1 | 0 0 0 |
|
||||
* | S2 | 0 0 1 |
|
||||
* | S3 | 0 1 0 |
|
||||
* | S4 | 0 1 1 |
|
||||
* | S5 | 1 0 0 |
|
||||
* | S6 | 1 0 1 |
|
||||
* | S7 | 1 1 0 |
|
||||
* | S8 | 1 1 1 |
|
||||
* +----+----------+
|
||||
*/
|
||||
static void ADG1408_select_channel(uint8_t selector)
|
||||
{
|
||||
struct ADG1408_pin_t adc_select;
|
||||
|
||||
switch (selector) {
|
||||
case ADG1408_S1:
|
||||
adc_select.A0 = 0;
|
||||
adc_select.A1 = 0;
|
||||
adc_select.A2 = 0;
|
||||
break;
|
||||
case ADG1408_S2:
|
||||
adc_select.A0 = 1;
|
||||
adc_select.A1 = 0;
|
||||
adc_select.A2 = 0;
|
||||
break;
|
||||
case ADG1408_S3:
|
||||
adc_select.A0 = 0;
|
||||
adc_select.A1 = 1;
|
||||
adc_select.A2 = 0;
|
||||
break;
|
||||
case ADG1408_S4:
|
||||
adc_select.A0 = 1;
|
||||
adc_select.A1 = 1;
|
||||
adc_select.A2 = 0;
|
||||
break;
|
||||
case ADG1408_S5:
|
||||
adc_select.A0 = 0;
|
||||
adc_select.A1 = 0;
|
||||
adc_select.A2 = 1;
|
||||
break;
|
||||
case ADG1408_S6:
|
||||
adc_select.A0 = 1;
|
||||
adc_select.A1 = 0;
|
||||
adc_select.A2 = 1;
|
||||
break;
|
||||
case ADG1408_S7:
|
||||
adc_select.A0 = 0;
|
||||
adc_select.A1 = 1;
|
||||
adc_select.A2 = 1;
|
||||
break;
|
||||
case ADG1408_S8:
|
||||
adc_select.A0 = 1;
|
||||
adc_select.A1 = 1;
|
||||
adc_select.A2 = 1;
|
||||
break;
|
||||
}
|
||||
|
||||
ADG1408_output(&adc_select);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@brief Select ADC channel.
|
||||
@param channel ADC_CH_VHP0 / ADC_CH_VHN0 / ADC_CH_IsenHP / ADC_CH_IsenHN
|
||||
ADC_CH_VHP12 / ADC_CH_Vdiff / ADC_CH_VHP1 / ADC_CH_VHN1
|
||||
*/
|
||||
void select_adc_channel(uint8_t channel)
|
||||
{
|
||||
static uint8_t last_channel = 0xFF;
|
||||
|
||||
if (last_channel == channel) {
|
||||
#if(!CC2650_CODE)
|
||||
NRF_LOG_INFO("select_adc_channel same channel(%d)", channel);
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
|
||||
switch (channel) {
|
||||
case ADC_CH_VHP0:
|
||||
ADG1408_select_channel(ADG1408_S1);
|
||||
break;
|
||||
case ADC_CH_VHN0:
|
||||
ADG1408_select_channel(ADG1408_S2);
|
||||
break;
|
||||
case ADC_CH_IsenHP:
|
||||
ADG1408_select_channel(ADG1408_S3);
|
||||
break;
|
||||
case ADC_CH_IsenHN:
|
||||
ADG1408_select_channel(ADG1408_S4);
|
||||
break;
|
||||
case ADC_CH_VHP12:
|
||||
ADG1408_select_channel(ADG1408_S5);
|
||||
break;
|
||||
case ADC_CH_Vdiff:
|
||||
ADG1408_select_channel(ADG1408_S6);
|
||||
break;
|
||||
case ADC_CH_VHP1:
|
||||
ADG1408_select_channel(ADG1408_S7);
|
||||
break;
|
||||
case ADC_CH_VHN1:
|
||||
ADG1408_select_channel(ADG1408_S8);
|
||||
break;
|
||||
}
|
||||
|
||||
last_channel = channel;
|
||||
}
|
||||
@@ -1,65 +1,245 @@
|
||||
#ifndef ADGS1412X2_H
|
||||
#define ADGS1412X2_H
|
||||
#include <stdint.h>
|
||||
#include "app_config.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#if(!CC2650_CODE)
|
||||
#include "nrf_log.h"
|
||||
#include "nrf_log_ctrl.h"
|
||||
#include "nrf_log_default_backends.h"
|
||||
#endif
|
||||
|
||||
|
||||
#define SIZE_OF_DAISY_CHAIN_COMMAND 2
|
||||
|
||||
|
||||
struct switch_series_data_t {
|
||||
uint8_t device8_switch;
|
||||
uint8_t device7_switch;
|
||||
uint8_t device6_switch;
|
||||
uint8_t device5_switch;
|
||||
uint8_t device4_switch;
|
||||
uint8_t device3_switch;
|
||||
uint8_t device2_switch;
|
||||
uint8_t device1_switch;
|
||||
}__attribute__((packed));
|
||||
|
||||
|
||||
enum ADGS1412_SWITCH_ENABLE_e {
|
||||
ALL_OPEN = 0x00, // 0b00000000
|
||||
SINGLE_S1 = 0x01, // 0b00000001
|
||||
SINGLE_S2 = 0x02, // 0b00000010
|
||||
S1_S2_ON = 0x03, // 0b00000011
|
||||
SINGLE_S3 = 0x04, // 0b00000100
|
||||
S3_S1_ON = 0x05, // 0b00000101
|
||||
S3_S2_ON = 0x06, // 0b00000110
|
||||
S3_S2_S1_ON = 0x07, // 0b00000111
|
||||
SINGLE_S4 = 0x08, // 0b00001000
|
||||
S4_S1_ON = 0x09, // 0b00001001
|
||||
S4_S2_ON = 0x0A, // 0b00001010
|
||||
S4_S2_S1_ON = 0x0B, // 0b00001011
|
||||
S4_S3_ON = 0x0C, // 0b00001100
|
||||
S4_S3_S1_ON = 0x0D, // 0b00001101
|
||||
S4_S3_S2_ON = 0x0E, // 0b00001110
|
||||
ALL_ON = 0x0F, // 0b00001111
|
||||
struct ADGS1412_component_conf_t {
|
||||
uint8_t U14;
|
||||
uint8_t U13;
|
||||
uint8_t U18;
|
||||
uint8_t U20;
|
||||
uint8_t U26;
|
||||
uint8_t U29;
|
||||
uint8_t U22;
|
||||
uint8_t U4;
|
||||
uint8_t U24;
|
||||
};
|
||||
|
||||
struct ADGS1412_component_conf_t ADGS1412_conf = {0};
|
||||
|
||||
enum ADGS1412_module_e {
|
||||
ADGS1412_MODULE_U14 = 0,
|
||||
ADGS1412_MODULE_U13,
|
||||
ADGS1412_MODULE_U18,
|
||||
ADGS1412_MODULE_U20,
|
||||
ADGS1412_MODULE_U26,
|
||||
ADGS1412_MODULE_U29,
|
||||
ADGS1412_MODULE_U22,
|
||||
ADGS1412_MODULE_U24,
|
||||
void ADGS1412_daisy_chain_mode(void)
|
||||
{
|
||||
uint8_t cmd_daisy_chain[2] = {0x25, 0x00};
|
||||
|
||||
ADGS1412_MODULE_MAX,
|
||||
};
|
||||
|
||||
|
||||
static struct switch_series_data_t switch_series_data_g = {0};
|
||||
|
||||
int switch_ctrl(uint8_t switch_module_number, uint8_t enable_type);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if(CC2650_CODE)
|
||||
spi1_open(SPI_CLK_12M, POL1, PHA0);
|
||||
set_pin_SWCSBB(0);
|
||||
spi1_write(NULL, cmd_daisy_chain, sizeof(cmd_daisy_chain));
|
||||
set_pin_SWCSBB(1);
|
||||
spi1_close();
|
||||
#else
|
||||
NRF_LOG_INFO("ADGS1412_daisy_chain_mode");
|
||||
NRF_LOG_HEXDUMP_INFO(cmd_daisy_chain, sizeof(cmd_daisy_chain));
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* spi:
|
||||
* |U14|U13|U18|U20|U26|U29|U22| U4|U24|
|
||||
*/
|
||||
static void ADGS1412_output(void)
|
||||
{
|
||||
uint8_t spi_array[9] = {ADGS1412_conf.U14, ADGS1412_conf.U13, ADGS1412_conf.U18,
|
||||
ADGS1412_conf.U20, ADGS1412_conf.U26, ADGS1412_conf.U29,
|
||||
ADGS1412_conf.U22, ADGS1412_conf.U4, ADGS1412_conf.U24};
|
||||
|
||||
#if(CC2650_CODE)
|
||||
spi1_open(SPI_CLK_12M, POL1, PHA0);
|
||||
set_pin_SWCSBB(0);
|
||||
spi1_write(spi_array, spi_array, sizeof(spi_array));
|
||||
set_pin_SWCSBB(1);
|
||||
spi1_close();
|
||||
#else
|
||||
NRF_LOG_HEXDUMP_INFO(spi_array, sizeof(spi_array));
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
* (0 = open circuit)
|
||||
* (1 = closed circuit)
|
||||
* +-----+-------------+
|
||||
* | | S4 S3 S2 S1 |
|
||||
* +-----+-------------+
|
||||
* | U14 | 0 0 0 0 |
|
||||
* | U13 | 0 0 0 0 |
|
||||
* | U18 | 0 0 0 0 |
|
||||
* | U20 | 1 1 1 1 |
|
||||
* | U26 | 0 0 0 0 |
|
||||
* | U29 | 0 0 0 0 |
|
||||
* | U22 | 0 0 0 0 |
|
||||
* | U4 | 1 0 0 0 |
|
||||
* | U24 | 0 0 1 0 |
|
||||
* +-----+-------------+
|
||||
*/
|
||||
void ADGS1412_idle_conf(void)
|
||||
{
|
||||
// if (ADGS1412_conf.U14 == ADGS1412_ALL_DIS &&
|
||||
// ADGS1412_conf.U13 == ADGS1412_ALL_DIS &&
|
||||
// ADGS1412_conf.U18 == ADGS1412_ALL_DIS &&
|
||||
// ADGS1412_conf.U20 == (ADGS1412_S1_EN | ADGS1412_S2_EN | ADGS1412_S3_EN | ADGS1412_S4_EN) &&
|
||||
// ADGS1412_conf.U26 == ADGS1412_ALL_DIS &&
|
||||
// ADGS1412_conf.U29 == ADGS1412_ALL_DIS &&
|
||||
// ADGS1412_conf.U22 == ADGS1412_ALL_DIS &&
|
||||
// ADGS1412_conf.U4 == ADGS1412_S4_EN &&
|
||||
// ADGS1412_conf.U24 == ADGS1412_S2_EN) {
|
||||
// #if(!CC2650_CODE)
|
||||
// NRF_LOG_INFO("ADGS1412_idle_conf same signal");
|
||||
// #endif
|
||||
// return;
|
||||
// }
|
||||
|
||||
#if(!CC2650_CODE)
|
||||
NRF_LOG_INFO("ADGS1412_idle_conf |U14|U13|U18|U20|U26|U29|U22| U4|U24|");
|
||||
#endif
|
||||
ADGS1412_conf.U14 = ADGS1412_ALL_DIS;
|
||||
ADGS1412_conf.U13 = ADGS1412_ALL_DIS;
|
||||
ADGS1412_conf.U18 = ADGS1412_ALL_DIS;
|
||||
ADGS1412_conf.U20 = ADGS1412_S1_EN | ADGS1412_S2_EN | ADGS1412_S3_EN | ADGS1412_S4_EN;
|
||||
ADGS1412_conf.U26 = ADGS1412_ALL_DIS;
|
||||
ADGS1412_conf.U29 = ADGS1412_ALL_DIS;
|
||||
ADGS1412_conf.U22 = ADGS1412_ALL_DIS;
|
||||
ADGS1412_conf.U4 = ADGS1412_S4_EN;
|
||||
ADGS1412_conf.U24 = ADGS1412_S2_EN;
|
||||
|
||||
ADGS1412_output();
|
||||
}
|
||||
|
||||
/**
|
||||
@brief Set status of ADGS1412 component.
|
||||
@param component_id ADGS1412_U14 / ADGS1412_U13 / ADGS1412_U18 /
|
||||
ADGS1412_U20 / ADGS1412_U26 / ADGS1412_U29 /
|
||||
ADGS1412_U22 / ADGS1412_U04 / ADGS1412_U24
|
||||
@param set_value ADGS1412_ALL_DIS / ADGS1412_S1_EN /ADGS1412_S2_EN /
|
||||
ADGS1412_S3_EN / ADGS1412_S4_EN
|
||||
*/
|
||||
void ADGS1412_set_one_mux(uint8_t component_id, uint8_t set_value)
|
||||
{
|
||||
switch (component_id) {
|
||||
case ADGS1412_U14:
|
||||
if (ADGS1412_conf.U14 == set_value) {
|
||||
#if(!CC2650_CODE)
|
||||
NRF_LOG_INFO("ADGS1412_set_one_mux(U14) same signal(%02x)", set_value);
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
ADGS1412_conf.U14 = set_value;
|
||||
break;
|
||||
case ADGS1412_U13:
|
||||
if (ADGS1412_conf.U13 == set_value) {
|
||||
#if(!CC2650_CODE)
|
||||
NRF_LOG_INFO("ADGS1412_set_one_mux(U13) same signal(%02x)", set_value);
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
ADGS1412_conf.U13 = set_value;
|
||||
break;
|
||||
case ADGS1412_U18:
|
||||
if (ADGS1412_conf.U18 == set_value) {
|
||||
#if(!CC2650_CODE)
|
||||
NRF_LOG_INFO("ADGS1412_set_one_mux(U18) same signal(%02x)", set_value);
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
ADGS1412_conf.U18 = set_value;
|
||||
break;
|
||||
case ADGS1412_U20:
|
||||
if (ADGS1412_conf.U20 == set_value) {
|
||||
#if(!CC2650_CODE)
|
||||
NRF_LOG_INFO("ADGS1412_set_one_mux(U20) same signal(%02x)", set_value);
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
ADGS1412_conf.U20 = set_value;
|
||||
break;
|
||||
case ADGS1412_U26:
|
||||
if (ADGS1412_conf.U26 == set_value) {
|
||||
#if(!CC2650_CODE)
|
||||
NRF_LOG_INFO("ADGS1412_set_one_mux(U26) same signal(%02x)", set_value);
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
ADGS1412_conf.U26 = set_value;
|
||||
break;
|
||||
case ADGS1412_U29:
|
||||
if (ADGS1412_conf.U29 == set_value) {
|
||||
#if(!CC2650_CODE)
|
||||
NRF_LOG_INFO("ADGS1412_set_one_mux(U29) same signal(%02x)", set_value);
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
ADGS1412_conf.U29 = set_value;
|
||||
break;
|
||||
case ADGS1412_U22:
|
||||
if (ADGS1412_conf.U22 == set_value) {
|
||||
#if(!CC2650_CODE)
|
||||
NRF_LOG_INFO("ADGS1412_set_one_mux(U22) same signal(%02x)", set_value);
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
ADGS1412_conf.U22 = set_value;
|
||||
break;
|
||||
case ADGS1412_U04:
|
||||
if (ADGS1412_conf.U4 == set_value) {
|
||||
#if(!CC2650_CODE)
|
||||
NRF_LOG_INFO("ADGS1412_set_one_mux(U04) same signal(%02x)", set_value);
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
ADGS1412_conf.U4 = set_value;
|
||||
break;
|
||||
case ADGS1412_U24:
|
||||
if (ADGS1412_conf.U24 == set_value) {
|
||||
#if(!CC2650_CODE)
|
||||
NRF_LOG_INFO("ADGS1412_set_one_mux(U24) same signal(%02x)", set_value);
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
ADGS1412_conf.U24 = set_value;
|
||||
break;
|
||||
}
|
||||
|
||||
ADGS1412_output();
|
||||
}
|
||||
|
||||
/**
|
||||
@brief Get status of ADGS1412 component.
|
||||
@param component_id ADGS1412_U14 / ADGS1412_U13 / ADGS1412_U18 /
|
||||
ADGS1412_U20 / ADGS1412_U26 / ADGS1412_U29 /
|
||||
ADGS1412_U22 / ADGS1412_U04 / ADGS1412_U24
|
||||
*/
|
||||
uint8_t ADGS1412_get_one_mux(uint8_t component_id)
|
||||
{
|
||||
if (component_id == ADGS1412_U14)
|
||||
return ADGS1412_conf.U14;
|
||||
|
||||
if (component_id == ADGS1412_U13)
|
||||
return ADGS1412_conf.U13;
|
||||
|
||||
if (component_id == ADGS1412_U18)
|
||||
return ADGS1412_conf.U18;
|
||||
|
||||
if (component_id == ADGS1412_U20)
|
||||
return ADGS1412_conf.U20;
|
||||
|
||||
if (component_id == ADGS1412_U26)
|
||||
return ADGS1412_conf.U26;
|
||||
|
||||
if (component_id == ADGS1412_U29)
|
||||
return ADGS1412_conf.U29;
|
||||
|
||||
if (component_id == ADGS1412_U22)
|
||||
return ADGS1412_conf.U22;
|
||||
|
||||
if (component_id == ADGS1412_U04)
|
||||
return ADGS1412_conf.U4;
|
||||
|
||||
if (component_id == ADGS1412_U24)
|
||||
return ADGS1412_conf.U24;
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -1,105 +0,0 @@
|
||||
#include "HAL/ADGS1412x9.h"
|
||||
|
||||
|
||||
static const uint8_t SPI_DAISY_CHAIN_COMMAND[2] = {0x25, 0x00};
|
||||
|
||||
static int __switch_transfer(struct switch_series_data_t *sd)
|
||||
{
|
||||
spi1_close();
|
||||
spi1_open(SPI_CLK_4M, POL0, PHA0);
|
||||
|
||||
pin_set(E_PIN_SWCSBB, 0);
|
||||
spi1_write(NULL, (uint8_t *)(sd), 8);
|
||||
pin_set(E_PIN_SWCSBB, 1);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int __switch_daisy_chain_mode() {
|
||||
spi1_close();
|
||||
spi1_open(SPI_CLK_4M, POL0, PHA0);
|
||||
|
||||
pin_set(E_PIN_SWCSBB, 0);
|
||||
spi1_write(NULL, SPI_DAISY_CHAIN_COMMAND, 2);
|
||||
pin_set(E_PIN_SWCSBB, 1);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int __set_switch_param(enum ADGS1412_module_e switch_module, enum ADGS1412_SWITCH_ENABLE_e enable_type, struct switch_series_data_t *switch_data)
|
||||
{
|
||||
struct switch_series_data_t *sd = switch_data;
|
||||
enum ADGS1412_module_e sw_module = switch_module;
|
||||
enum ADGS1412_SWITCH_ENABLE_e en_type = enable_type;
|
||||
|
||||
switch(sw_module) {
|
||||
case ADGS1412_MODULE_U14:
|
||||
sd->device8_switch = (uint8_t)en_type;
|
||||
break;
|
||||
|
||||
case ADGS1412_MODULE_U13:
|
||||
sd->device7_switch = (uint8_t)en_type;
|
||||
break;
|
||||
|
||||
case ADGS1412_MODULE_U18:
|
||||
sd->device6_switch = (uint8_t)en_type;
|
||||
break;
|
||||
|
||||
case ADGS1412_MODULE_U20:
|
||||
sd->device5_switch = (uint8_t)en_type;
|
||||
break;
|
||||
|
||||
case ADGS1412_MODULE_U26:
|
||||
sd->device4_switch = (uint8_t)en_type;
|
||||
break;
|
||||
|
||||
case ADGS1412_MODULE_U29:
|
||||
sd->device3_switch = (uint8_t)en_type;
|
||||
break;
|
||||
|
||||
case ADGS1412_MODULE_U22:
|
||||
sd->device2_switch = (uint8_t)en_type;
|
||||
break;
|
||||
|
||||
case ADGS1412_MODULE_U24:
|
||||
sd->device1_switch = (uint8_t)en_type;
|
||||
break;
|
||||
case ADGS1412_MODULE_MAX:
|
||||
*sd = (struct switch_series_data_t) {.device8_switch = (uint8_t)en_type,
|
||||
.device7_switch = (uint8_t)en_type,
|
||||
.device6_switch = (uint8_t)en_type,
|
||||
.device5_switch = (uint8_t)en_type,
|
||||
.device4_switch = (uint8_t)en_type,
|
||||
.device3_switch = (uint8_t)en_type,
|
||||
.device2_switch = (uint8_t)en_type,
|
||||
.device1_switch = (uint8_t)en_type,
|
||||
};
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int switch_ctrl(uint8_t switch_module_number, uint8_t enable_type)
|
||||
{
|
||||
|
||||
struct switch_series_data_t *sd = &switch_series_data_g;
|
||||
enum ADGS1412_module_e sw_module = (enum ADGS1412_module_e) switch_module_number;
|
||||
enum ADGS1412_SWITCH_ENABLE_e en_type = (enum ADGS1412_SWITCH_ENABLE_e) enable_type;
|
||||
|
||||
if(sw_module > ADGS1412_MODULE_MAX)
|
||||
return -1;
|
||||
|
||||
if(en_type > ALL_ON)
|
||||
return -2;
|
||||
|
||||
if (sw_module == ADGS1412_MODULE_U24 && en_type == S1_S2_ON)
|
||||
return -3;
|
||||
|
||||
__switch_daisy_chain_mode();
|
||||
__set_switch_param(sw_module, en_type, sd);
|
||||
__switch_transfer(sd);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,330 @@
|
||||
/*
|
||||
* ADS8691
|
||||
* Features:
|
||||
* -18-Bit ADC With Integrated Analog Front-End
|
||||
* -High Speed: 1 MSPS
|
||||
*
|
||||
* Spi data:
|
||||
* 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
|
||||
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
* | Input | 9-bit address | 16-bit data |
|
||||
* | Commands | | |
|
||||
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
*
|
||||
* -CMD [7bits]
|
||||
* 0b11000xx CLEAR_HWORD
|
||||
* 0b11001xx READ_HWORD
|
||||
* 0b01001xx READ
|
||||
* 0b1101000 WRITE (We used this CMD)
|
||||
* 0b1101001 WRITE
|
||||
* 0b1101010 WRITE
|
||||
* 0b11011xx SET_HWORD
|
||||
*
|
||||
* -Address [9bits]
|
||||
* 00h DEVICE_ID_REG
|
||||
* 04h RST_PWRCTL_REG
|
||||
* 08h SDI_CTL_REG
|
||||
* 0Ch SDO_CTL_REG
|
||||
* 10h DATAOUT_CTL_REG
|
||||
* 14h RANGE_SEL_REG
|
||||
* 20h ALARM_REG
|
||||
* 24h ALARM_H_TH_REG
|
||||
* 28h ALARM_L_TH_REG
|
||||
*
|
||||
*/
|
||||
#include <stdint.h>
|
||||
#include "app_config.h"
|
||||
|
||||
#if(!CC2650_CODE)
|
||||
#include "nrf_log.h"
|
||||
#include "nrf_log_ctrl.h"
|
||||
#include "nrf_log_default_backends.h"
|
||||
#endif
|
||||
|
||||
static uint8_t ADC_input_range = 0xFF;
|
||||
|
||||
#define ADS8691_CMD_WRITE 0b1101000
|
||||
|
||||
#define ADS8691_ADDRESS_RST_PWRCTL_REG 0x0004
|
||||
#define ADS8691_ADDRESS_SDI_CTL_REG 0x0008
|
||||
#define ADS8691_ADDRESS_DATAOUT_CTL_REG 0x0010
|
||||
#define ADS8691_ADDRESS_RANGE_SEL_REG 0x0014
|
||||
|
||||
static uint32_t ADS8691_write_spi(uint8_t command, uint16_t address, uint16_t data)
|
||||
{
|
||||
uint8_t spi_array[4];
|
||||
|
||||
spi_array[0] = command<<1 | address>>8;
|
||||
spi_array[1] = address & 0xFF;
|
||||
spi_array[2] = HIGH_BYTES_16b(data);
|
||||
spi_array[3] = LOW_BYTES_16b(data);
|
||||
|
||||
#if(CC2650_CODE)
|
||||
spi1_open(SPI_CLK_12M, POL1, PHA0);
|
||||
set_pin_ADCCS(0);
|
||||
spi1_write(spi_array, spi_array, sizeof(spi_array));
|
||||
set_pin_ADCCS(1);
|
||||
spi1_close();
|
||||
#else
|
||||
NRF_LOG_INFO("ADS8691_write_spi");
|
||||
NRF_LOG_HEXDUMP_INFO(spi_array, sizeof(spi_array));
|
||||
spi_array[0] = 0x8c;//0x8C8F4400
|
||||
spi_array[1] = 0x8f;//0x8C8F4400
|
||||
spi_array[2] = 0x44;//0x8C8F4400
|
||||
spi_array[3] = 0x00;//0x8C8F4400
|
||||
#endif
|
||||
|
||||
uint32_t value = spi_array[0]<<24 | spi_array[1]<<16 | spi_array[2]<<8 | spi_array[3];
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
/**** SDI_CTL_REG Register ******************************************************************************/
|
||||
static void set_ads8691_spi_mode_as_pol1_pha0(void)
|
||||
{
|
||||
struct para_SDI_CTL_REG_t {
|
||||
uint16_t rsvd_1:14,
|
||||
SDI_MODE:2;
|
||||
};
|
||||
|
||||
#if(!CC2650_CODE)
|
||||
NRF_LOG_INFO("ADC set_ads8691_spi_mode_as_pol1_pha0");
|
||||
#endif
|
||||
struct para_SDI_CTL_REG_t reg_data = {0};
|
||||
uint16_t val;
|
||||
|
||||
// set conf
|
||||
reg_data.SDI_MODE = 0x02;
|
||||
|
||||
// combine
|
||||
val = reg_data.SDI_MODE;
|
||||
|
||||
ADS8691_write_spi(ADS8691_CMD_WRITE, ADS8691_ADDRESS_SDI_CTL_REG, val);
|
||||
}
|
||||
|
||||
/**** RST_PWRCTL_REG Register ******************************************************************************/
|
||||
static void reset_quickly(void)
|
||||
{
|
||||
struct para_RST_PWRCTL_REG_t {
|
||||
uint16_t WKEY:8,
|
||||
rsvd_1:2,
|
||||
VDD_AL_DIS:1,
|
||||
IN_AL_DIS:1,
|
||||
rsvd_2:1,
|
||||
RSTn_APP:1,
|
||||
NAP_EN:1,
|
||||
PWRDN:1;
|
||||
};
|
||||
|
||||
#if(!CC2650_CODE)
|
||||
NRF_LOG_INFO("ADC reset_quickly");
|
||||
#endif
|
||||
struct para_RST_PWRCTL_REG_t reg_data = {0};
|
||||
uint16_t val;
|
||||
|
||||
// set conf
|
||||
reg_data.WKEY = 0x69;
|
||||
reg_data.RSTn_APP = 1;
|
||||
|
||||
// combine
|
||||
val = reg_data.WKEY<<8 | reg_data.VDD_AL_DIS<<5 |
|
||||
reg_data.IN_AL_DIS<<4 | reg_data.RSTn_APP<<2 |
|
||||
reg_data.NAP_EN<<1 | reg_data.PWRDN;
|
||||
|
||||
ADS8691_write_spi(ADS8691_CMD_WRITE, ADS8691_ADDRESS_RST_PWRCTL_REG, val);
|
||||
}
|
||||
|
||||
/**** DATAOUT_CTL_REG Register ******************************************************************************/
|
||||
static uint32_t get_18bit_adc_value(void)
|
||||
{
|
||||
struct para_DATAOUT_CTL_REG_t {
|
||||
uint16_t rsvd_1:1,
|
||||
DEVICE_ADDR_INCL:1,
|
||||
VDD_ACTIVE_ALARM_INCL:2,
|
||||
IN_ACTIVE_ALARM_INCL:2,
|
||||
rsvd_2:1,
|
||||
RANGE_INCL:1,
|
||||
rsvd_3:4,
|
||||
PAR_EN:1,
|
||||
DATA_VAL:3;
|
||||
};
|
||||
#if(!CC2650_CODE)
|
||||
NRF_LOG_INFO("get_18bit_adc_value()");
|
||||
#endif
|
||||
struct para_DATAOUT_CTL_REG_t reg_data = {0};
|
||||
uint32_t spi_rx;
|
||||
uint16_t val;
|
||||
|
||||
// set conf
|
||||
reg_data.RANGE_INCL = 1;
|
||||
|
||||
// combine
|
||||
val = reg_data.DEVICE_ADDR_INCL<<14 | reg_data.VDD_ACTIVE_ALARM_INCL<<12 |
|
||||
reg_data.IN_ACTIVE_ALARM_INCL<<10 | reg_data.RANGE_INCL<<8 |
|
||||
reg_data.PAR_EN<<3 | reg_data.DATA_VAL;
|
||||
|
||||
spi_rx = ADS8691_write_spi(ADS8691_CMD_WRITE, ADS8691_ADDRESS_DATAOUT_CTL_REG, val);
|
||||
|
||||
return spi_rx>>14;
|
||||
}
|
||||
|
||||
/**** RANGE_SEL_REG Register ******************************************************************************/
|
||||
#define p_n_3_0_Vref 0b0000 //ADC measure range: +-12.288V LSB:93.75uV
|
||||
#define p_n_2_5_Vref 0b0001 //ADC measure range: +-10.24V LSB:78.125uV
|
||||
#define p_n_1_5_Vref 0b0010 //ADC measure range: +-6.144V LSB:46.875uV
|
||||
#define p_n_1_25_Vref 0b0011 //ADC measure range: +-5.12V LSB:39.06uV
|
||||
#define p_n_0_625_Vref 0b0100 //ADC measure range: +-2.56V LSB:19.53uV
|
||||
#define p_3_0_Vref 0b1000 //ADC measure range: 0V ~ +12.288V LSB:46.875uV
|
||||
#define p_2_5_Vref 0b1001 //ADC measure range: 0V ~ +10.24V LSB:39.06uV
|
||||
#define p_1_5_Vref 0b1010 //ADC measure range: 0V ~ +6.144V LSB:23.43uV
|
||||
#define p_1_25_Vref 0b1011 //ADC measure range: 0V ~ +5.12V LSB:19.53uV
|
||||
int8_t set_adc_input_range(uint8_t range)
|
||||
{
|
||||
struct para_RANGE_SEL_REG_t {
|
||||
uint16_t rsvd_1:8,
|
||||
rsvd_2:1,
|
||||
INTREF_DIS:1,
|
||||
rsvd_3:2,
|
||||
RANGE_SEL:4;
|
||||
};
|
||||
|
||||
struct para_RANGE_SEL_REG_t reg_data = {0};
|
||||
uint16_t val;
|
||||
|
||||
if (ADC_input_range == range) {
|
||||
#if(!CC2650_CODE)
|
||||
NRF_LOG_INFO("set_adc_input_range same range");
|
||||
#endif
|
||||
return -1;
|
||||
}
|
||||
|
||||
#if(!CC2650_CODE)
|
||||
NRF_LOG_INFO("set_adc_input_range(%d)", range);
|
||||
#endif
|
||||
|
||||
// set conf
|
||||
switch (range) {
|
||||
case ADC_MEASURE_RANGE_12V_PN:
|
||||
reg_data.RANGE_SEL = p_n_3_0_Vref;
|
||||
break;
|
||||
case ADC_MEASURE_RANGE_10V_PN:
|
||||
reg_data.RANGE_SEL = p_n_2_5_Vref;
|
||||
break;
|
||||
case ADC_MEASURE_RANGE_06V_PN:
|
||||
reg_data.RANGE_SEL = p_n_1_5_Vref;
|
||||
break;
|
||||
case ADC_MEASURE_RANGE_05V_PN:
|
||||
reg_data.RANGE_SEL = p_n_1_25_Vref;
|
||||
break;
|
||||
case ADC_MEASURE_RANGE_02V_PN:
|
||||
reg_data.RANGE_SEL = p_n_0_625_Vref;
|
||||
break;
|
||||
// case p_3_0_Vref:
|
||||
// reg_data.RANGE_SEL = p_3_0_Vref;
|
||||
// break;
|
||||
// case p_2_5_Vref:
|
||||
// reg_data.RANGE_SEL = p_2_5_Vref;
|
||||
// break;
|
||||
// case p_1_5_Vref:
|
||||
// reg_data.RANGE_SEL = p_1_5_Vref;
|
||||
// break;
|
||||
// case p_1_25_Vref:
|
||||
// reg_data.RANGE_SEL = p_1_25_Vref;
|
||||
// break;
|
||||
}
|
||||
|
||||
// combine
|
||||
val = reg_data.INTREF_DIS<<6 | reg_data.RANGE_SEL;
|
||||
ADS8691_write_spi(ADS8691_CMD_WRITE, ADS8691_ADDRESS_RANGE_SEL_REG, val);
|
||||
ADC_input_range = range;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t get_adc_input_range(void)
|
||||
{
|
||||
return ADC_input_range;
|
||||
}
|
||||
|
||||
int32_t get_adc_voltage_uV(void)
|
||||
{
|
||||
|
||||
uint32_t adc_raw = get_18bit_adc_value();
|
||||
int64_t adc_voltage_uV;
|
||||
|
||||
if (ADC_input_range == ADC_MEASURE_RANGE_12V_PN)
|
||||
adc_voltage_uV = (int64_t)adc_raw * 93.75 - 12288000; //uV
|
||||
else if (ADC_input_range == ADC_MEASURE_RANGE_10V_PN)
|
||||
adc_voltage_uV = (int64_t)adc_raw * 78.125 - 10240000; //uV
|
||||
else if (ADC_input_range == ADC_MEASURE_RANGE_06V_PN)
|
||||
adc_voltage_uV = (int64_t)adc_raw * 46.875 - 6144000; //uV
|
||||
else if (ADC_input_range == ADC_MEASURE_RANGE_05V_PN)
|
||||
adc_voltage_uV = (int64_t)adc_raw * 39.06 - 5120000; //uV
|
||||
else if (ADC_input_range == ADC_MEASURE_RANGE_02V_PN)
|
||||
adc_voltage_uV = (int64_t)adc_raw * 19.53 - 2560000; //uV
|
||||
|
||||
#if(!CC2650_CODE)
|
||||
NRF_LOG_INFO("get_adc_voltage_uV adc_raw=%d, adc_voltage_uV=%d", adc_raw, adc_voltage_uV);
|
||||
#endif
|
||||
|
||||
return (int32_t)adc_voltage_uV;
|
||||
}
|
||||
|
||||
int32_t get_adc_HPvoltage_uV(void)
|
||||
{
|
||||
|
||||
uint32_t adc_raw = get_18bit_adc_value(); //max:262143
|
||||
int64_t adc_voltage_uV;
|
||||
|
||||
if (ADC_input_range == ADC_MEASURE_RANGE_12V_PN)
|
||||
adc_voltage_uV = (int64_t)adc_raw * 93.75 - 12288000; //uV
|
||||
else if (ADC_input_range == ADC_MEASURE_RANGE_10V_PN)
|
||||
adc_voltage_uV = (int64_t)adc_raw * 78.125 - 10240000; //uV
|
||||
else if (ADC_input_range == ADC_MEASURE_RANGE_06V_PN)
|
||||
adc_voltage_uV = (int64_t)adc_raw * 46.875 - 6144000; //uV
|
||||
else if (ADC_input_range == ADC_MEASURE_RANGE_05V_PN)
|
||||
adc_voltage_uV = (int64_t)adc_raw * 39.06 - 5120000; //uV
|
||||
else if (ADC_input_range == ADC_MEASURE_RANGE_02V_PN)
|
||||
adc_voltage_uV = (int64_t)adc_raw * 19.53 - 2560000; //uV
|
||||
|
||||
#if(!CC2650_CODE)
|
||||
NRF_LOG_INFO("get_adc_voltage_uV adc_raw=%d, adc_voltage_uV=%d", adc_raw, adc_voltage_uV);
|
||||
#endif
|
||||
|
||||
return (int32_t)adc_voltage_uV;
|
||||
}
|
||||
|
||||
int32_t get_adc_HNvoltage_uV(void)
|
||||
{
|
||||
|
||||
uint32_t adc_raw = get_18bit_adc_value();
|
||||
notify_ch6 = adc_raw;
|
||||
int64_t adc_voltage_uV;
|
||||
|
||||
if (ADC_input_range == ADC_MEASURE_RANGE_12V_PN)
|
||||
adc_voltage_uV = (int64_t)adc_raw * 93.75 - 12288000; //uV
|
||||
else if (ADC_input_range == ADC_MEASURE_RANGE_10V_PN)
|
||||
adc_voltage_uV = (int64_t)adc_raw * 78.125 - 10240000; //uV
|
||||
else if (ADC_input_range == ADC_MEASURE_RANGE_06V_PN)
|
||||
adc_voltage_uV = (int64_t)adc_raw * 46.875 - 6144000; //uV
|
||||
else if (ADC_input_range == ADC_MEASURE_RANGE_05V_PN)
|
||||
adc_voltage_uV = (int64_t)adc_raw * 39.06 - 5120000; //uV
|
||||
else if (ADC_input_range == ADC_MEASURE_RANGE_02V_PN)
|
||||
adc_voltage_uV = (int64_t)adc_raw * 19.53 - 2560000; //uV
|
||||
|
||||
#if(!CC2650_CODE)
|
||||
NRF_LOG_INFO("get_adc_voltage_uV adc_raw=%d, adc_voltage_uV=%d", adc_raw, adc_voltage_uV);
|
||||
#endif
|
||||
|
||||
return (int32_t)adc_voltage_uV;
|
||||
}
|
||||
|
||||
/*
|
||||
* initial 18-Bit ADC
|
||||
* -reset quickly
|
||||
*/
|
||||
void ADS8691_init(void)
|
||||
{
|
||||
set_ads8691_spi_mode_as_pol1_pha0();
|
||||
reset_quickly();
|
||||
}
|
||||
@@ -113,8 +113,9 @@ static int __led_color_set(enum led_series_nb_e led_nb, struct led_frame_t *led_
|
||||
}
|
||||
|
||||
__led_complete(sd);
|
||||
|
||||
spi0_open(SPI_CLK_10M, POL0, PHA1); //10M // SPI0 = LED
|
||||
spi0_write(NULL, (void *)(sd), sizeof(struct led_series_data_t));
|
||||
spi0_close();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1,61 +1,137 @@
|
||||
#ifndef MAX5136X2_H
|
||||
#define MAX5136X2_H
|
||||
/*
|
||||
* MAX5136
|
||||
* CLR: Software clear.
|
||||
* 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3
|
||||
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
* |0 0 0 0 0 0 1 0|x x x x x x x x|x x x x x x x x|
|
||||
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
*
|
||||
* Write-through: Write to selected input and DAC registers, DAC outputs updated(writethrough).
|
||||
* 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3
|
||||
* +-+-+-+-+--+--+--+--+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
* |0 0 1 1 D3 D2 D1 D0| dac_code |
|
||||
* +-+-+-+-+--+--+--+--+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
*/
|
||||
#include <stdint.h>
|
||||
#include "app_config.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#if(!CC2650_CODE)
|
||||
#include "nrf_log.h"
|
||||
#include "nrf_log_ctrl.h"
|
||||
#include "nrf_log_default_backends.h"
|
||||
#endif
|
||||
|
||||
#define REVERT_2_BYTE(_b) ((_b) >> 8 | (((_b) & 0xFF) << 8))
|
||||
// Elite Conponent id:
|
||||
#define COMPONENT_DAC_U38 0x00 // spi_sequence:first
|
||||
#define COMPONENT_DAC_U37 0x01 // spi_sequence:second
|
||||
#define COMPONENT_DAC_MAX 0x02
|
||||
|
||||
#define MAX5136_NUM_MAX 2
|
||||
#define SIZEOFDAC_SPI MAX5136_NUM_MAX*3
|
||||
// MAX5136 Command Codes
|
||||
#define MAX5136_CMD_NOP 0x00 //!< No operation
|
||||
#define MAX5136_CMD_UPDATE 0x01 //!< Move contents of input to DAC registers indicated by 1’s. No effect on registers indicated by 0’s.
|
||||
#define MAX5136_CMD_CLR 0x02 //!< Software clear.
|
||||
#define MAX5136_CMD_POWER_DOWN 0x03 //!< Power down n
|
||||
#define MAX5136_CMD_OPTIMIZE 0x05 //!< Optimize DAC linearity.
|
||||
#define MAX5136_CMD_WRITE 0x10 //!< Write to selected input registers (DAC output not affected).
|
||||
#define MAX5136_CMD_WRITE_UPDATE 0x30 //!< Write to selected input and DAC registers, DAC outputs updated(writethrough).
|
||||
|
||||
#define CTRL_B_LDAC 0x01
|
||||
#define CTRL_B_CLR 0x02
|
||||
#define CTRL_B_POW_CTRL 0x03
|
||||
#define CTRL_B_LINEARITY 0x05
|
||||
#define CTRL_B_WRT(_d0, _d1) (0x10 | ((_d1) << 1) | (_d0))
|
||||
#define CTRL_B_WRT_THR(_d0, _d1) (0x30 | ((_d1) << 1) | (_d0))
|
||||
// Internal pins of MAX5136
|
||||
#define MAX5136_OUT0 0x01
|
||||
#define MAX5136_OUT1 0x02
|
||||
#define MAX5136_OUT2 0x04 // MAX5136 isn't exist
|
||||
#define MAX5136_OUT3 0x08 // MAX5136 isn't exist
|
||||
#define MAX5136_OUT_ALL 0x0F
|
||||
|
||||
#define DATA_B_LDAC(_d0, _d1) ((_d1) << 9 | (_d0) << 8)
|
||||
#define DATA_B_POW_CT(_d0, _d1, _rd) ((_d1) << 9 | (_d0) << 8 | (_rd) << 7)
|
||||
#define DATA_B_LINE(_en) ((_en) << 9)
|
||||
|
||||
#define DAC0_EN 1
|
||||
#define DAC0_DIS 0
|
||||
#define DAC1_EN 1
|
||||
#define DAC1_DIS 0
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
enum MAX5136_num_e {
|
||||
DAC_NB_0 = 0x00,
|
||||
DAC_NB_1,
|
||||
DAC_NB_MAX = 0x02,
|
||||
struct max5136_dac_code_t {
|
||||
uint16_t out0_dac_code;
|
||||
uint16_t out1_dac_code;
|
||||
};
|
||||
|
||||
struct max5136_dac_code_t max5136_u38 = {0};
|
||||
struct max5136_dac_code_t max5136_u37 = {0};
|
||||
|
||||
|
||||
|
||||
struct dac_series_control_t
|
||||
/**
|
||||
@brief Use write through mode to control U37 & U38 output.
|
||||
(The option is limited to selecting a single chip(component) for control.
|
||||
But could control OUT0~OUT3 on one chip.)
|
||||
@param dac_component COMPONENT_DAC_U37 / COMPONENT_DAC_U38
|
||||
@param dac_command MAX5136_CMD_WRITE_UPDATE / MAX5136_CMD_CLR / ...
|
||||
@param dac_address MAX5136_OUT1 / MAX5136_OUT2
|
||||
@param dac_code 0-65535
|
||||
*/
|
||||
static void MAX5136_write_through(uint8_t dac_component, uint8_t dac_command, uint8_t dac_address, uint16_t dac_code)
|
||||
{
|
||||
uint8_t dac0_enable;
|
||||
uint8_t dac1_enable;
|
||||
uint16_t volts;
|
||||
}__attribute__((packed));
|
||||
uint8_t spi_array[3 * COMPONENT_DAC_MAX] = {0};
|
||||
|
||||
spi_array[dac_component*3+0] = dac_command | dac_address;
|
||||
spi_array[dac_component*3+1] = HIGH_BYTES_16b(dac_code);
|
||||
spi_array[dac_component*3+2] = LOW_BYTES_16b(dac_code);
|
||||
|
||||
struct dac_series_control_t dac_series_control_g[MAX5136_NUM_MAX] = {0};
|
||||
|
||||
|
||||
|
||||
//int dac_write_through_mode(uint8_t dac0_enable, uint8_t dac1_enable, uint16_t volts, struct dac_series_data_t *sd_dac);
|
||||
// int dac_series_control_clear();
|
||||
int dac_enable_all_output(struct dac_series_control_t *seriesPtr);
|
||||
int dac_enable_single_output(uint8_t dac0_enable, uint8_t dac1_enable, uint16_t volts, enum MAX5136_num_e dac_num);
|
||||
#ifdef __cplusplus
|
||||
#if(CC2650_CODE)
|
||||
spi1_open(SPI_CLK_12M, POL1, PHA0);
|
||||
set_pin_DACCS(0);
|
||||
spi1_write(spi_array, spi_array, sizeof(spi_array));
|
||||
set_pin_DACCS(1);
|
||||
spi1_close();
|
||||
#else
|
||||
NRF_LOG_INFO("MAX5136_write_through");
|
||||
NRF_LOG_HEXDUMP_INFO(spi_array, sizeof(spi_array));
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
@brief Configure the voltage of external OUT_0 to OUT_3 pins on the two MAX5136 chips.
|
||||
@param out_pin DAC_OUT_0 / DAC_OUT_1 / DAC_OUT_2 / DAC_OUT_3
|
||||
@param dac_code 0-65535
|
||||
example:
|
||||
if you want to set OUT_3 pin voltage: 1.22V
|
||||
fomular: 2.44 * dac_code / 65536 = OUT_x's voltage
|
||||
-> 2.44 * dac_code / 65536 = 1.22V
|
||||
-> so dac_code = 32768
|
||||
-> call OUT_n_output(DAC_OUT_3, 32768);
|
||||
*/
|
||||
void OUT_n_output(uint8_t out_pin, uint16_t dac_code)
|
||||
{
|
||||
switch (out_pin) {
|
||||
case DAC_OUT_0:
|
||||
if (max5136_u38.out0_dac_code == dac_code) {
|
||||
#if(!CC2650_CODE)
|
||||
NRF_LOG_INFO("OUT_n_output(OUT_0) same dac code(%02x)", dac_code);
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
max5136_u38.out0_dac_code = dac_code;
|
||||
MAX5136_write_through(COMPONENT_DAC_U38, MAX5136_CMD_WRITE_UPDATE, MAX5136_OUT0, max5136_u38.out0_dac_code);
|
||||
break;
|
||||
case DAC_OUT_1:
|
||||
if (max5136_u38.out1_dac_code == dac_code) {
|
||||
#if(!CC2650_CODE)
|
||||
NRF_LOG_INFO("OUT_n_output(OUT_1) same dac code(%02x)", dac_code);
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
max5136_u38.out1_dac_code = dac_code;
|
||||
MAX5136_write_through(COMPONENT_DAC_U38, MAX5136_CMD_WRITE_UPDATE, MAX5136_OUT1, max5136_u38.out1_dac_code);
|
||||
break;
|
||||
case DAC_OUT_2:
|
||||
if (max5136_u37.out0_dac_code == dac_code) {
|
||||
#if(!CC2650_CODE)
|
||||
NRF_LOG_INFO("OUT_n_output(OUT_2) same dac code(%02x)", dac_code);
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
max5136_u37.out0_dac_code = dac_code;
|
||||
MAX5136_write_through(COMPONENT_DAC_U37, MAX5136_CMD_WRITE_UPDATE, MAX5136_OUT0, max5136_u37.out0_dac_code);
|
||||
break;
|
||||
case DAC_OUT_3:
|
||||
if (max5136_u37.out1_dac_code == dac_code) {
|
||||
#if(!CC2650_CODE)
|
||||
NRF_LOG_INFO("OUT_n_output(OUT_3) same dac code(%02x)", dac_code);
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
max5136_u37.out1_dac_code = dac_code;
|
||||
MAX5136_write_through(COMPONENT_DAC_U37, MAX5136_CMD_WRITE_UPDATE, MAX5136_OUT1, max5136_u37.out1_dac_code);
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -1,121 +0,0 @@
|
||||
/*
|
||||
* MAX5136
|
||||
* CLR: Software clear.
|
||||
* 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3
|
||||
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
* |0 0 0 0 0 0 1 0|x x x x x x x x|x x x x x x x x|
|
||||
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
*
|
||||
* Write-through: Write to selected input and DAC registers, DAC outputs updated(writethrough).
|
||||
* 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3
|
||||
* +-+-+-+-+--+--+--+--+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
* |0 0 1 1 D3 D2 D1 D0| DAC data |
|
||||
* +-+-+-+-+--+--+--+--+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
*/
|
||||
#include "HAL/MAX5136x2.h"
|
||||
#include "HAL/cc2650_driver/spi_ctrl.h"
|
||||
|
||||
struct dac_series_data_t {
|
||||
uint8_t control_bits;
|
||||
uint16_t data_bits;
|
||||
}__attribute__((packed));
|
||||
|
||||
|
||||
static struct dac_series_data_t dac_series_data_g[MAX5136_NUM_MAX] = {0};
|
||||
|
||||
|
||||
static int __dac_transfer(struct dac_series_data_t *sd)
|
||||
{
|
||||
|
||||
|
||||
spi1_close();
|
||||
spi1_open(SPI_CLK_4M, POL1, PHA0);
|
||||
|
||||
pin_set(E_PIN_DACCS, 0);
|
||||
spi1_write(NULL, (uint8_t *)(sd), SIZEOFDAC_SPI);
|
||||
pin_set(E_PIN_DACCS, 1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int __dac_write_through_mode(uint8_t dac0_enable, uint8_t dac1_enable, uint16_t volts, struct dac_series_data_t *sd_dac)
|
||||
{
|
||||
uint8_t d0 = dac0_enable;
|
||||
uint8_t d1 = dac1_enable;
|
||||
uint16_t v = volts;
|
||||
|
||||
struct dac_series_data_t *sd = sd_dac;
|
||||
|
||||
sd->control_bits = CTRL_B_WRT_THR(d0, d1);
|
||||
sd->data_bits = REVERT_2_BYTE(v);
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int dac_series_control_clear() {
|
||||
for(int i = DAC_NB_0; i < DAC_NB_MAX; i++) {
|
||||
dac_series_control_g[i].dac0_enable = 0;
|
||||
dac_series_control_g[i].dac1_enable = 0;
|
||||
dac_series_control_g[i].volts = 0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int dac_enable_all_output(struct dac_series_control_t *seriesPtr)
|
||||
{
|
||||
struct dac_series_data_t *sd = dac_series_data_g;
|
||||
|
||||
for(int i = DAC_NB_0; i < DAC_NB_MAX; i++) {
|
||||
if (seriesPtr[i].dac0_enable || seriesPtr[i].dac1_enable) {
|
||||
uint8_t dac0_en = seriesPtr[i].dac0_enable;
|
||||
uint8_t dac1_en = seriesPtr[i].dac1_enable;
|
||||
uint16_t v = seriesPtr[i].volts;
|
||||
__dac_write_through_mode(dac0_en, dac1_en, v, (sd + i));
|
||||
}
|
||||
}
|
||||
|
||||
__dac_transfer(sd);
|
||||
|
||||
dac_series_control_clear();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int dac_enable_single_output(uint8_t dac0_enable, uint8_t dac1_enable, uint16_t volts, enum MAX5136_num_e dac_num) {
|
||||
uint8_t dac0_en = dac0_enable;
|
||||
uint8_t dac1_en = dac1_enable;
|
||||
uint16_t v = volts;
|
||||
enum MAX5136_num_e dac_n = dac_num;
|
||||
struct dac_series_data_t *sd = dac_series_data_g;
|
||||
|
||||
if(dac_n >= DAC_NB_MAX)
|
||||
return -1;
|
||||
|
||||
for(int i = DAC_NB_0; i < DAC_NB_MAX; i++) {
|
||||
if(i == dac_n)
|
||||
__dac_write_through_mode(dac0_en, dac1_en, v, (sd+i));
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,29 +1,55 @@
|
||||
#ifndef MCP23008X2_H
|
||||
#define MCP23008X2_H
|
||||
/*
|
||||
* MCP23008: Series data structure
|
||||
* I2C
|
||||
* -Write:
|
||||
* +---------------------+------------------------+-------------+
|
||||
* | Device Opcode(1B) | Register Address(1B) | Value(1B) |
|
||||
* +---------------------+------------------------+-------------+
|
||||
* / \
|
||||
* / Device Opcode(1B)\
|
||||
* / \
|
||||
* 0 1 2 3 4 5 6 7
|
||||
* +-+-+-+-+--+--+--+---+
|
||||
* | 0100 |A2 A1 A0 R/W|
|
||||
* +-+-+-+-+--+--+--+---+ (CC2650's I2C could read and write in the same time)
|
||||
* ps.CC2650 I2C parameter: -> U503(PB) set GPIO=74h | U505(PA) set GPIO=45h
|
||||
* I2C_addr = 0b 0 1 0 0 A2 A1 A0 -> 0b0100011 = [23h] | 0b0100110 = [26h]
|
||||
* tx = Register Address + Value -> [09h 74h] | [09h 45h]
|
||||
* txlen=2
|
||||
* rxlen=2
|
||||
*
|
||||
*
|
||||
* -Read:
|
||||
* +---------------------+------------------------+
|
||||
* | Device Opcode(1B) | Register Address(1B) |
|
||||
* +---------------------+------------------------+
|
||||
* / \
|
||||
* / Device Opcode(1B)\
|
||||
* / \
|
||||
* 0 1 2 3 4 5 6 7
|
||||
* +-+-+-+-+--+--+--+---+
|
||||
* | 0100 |A2 A1 A0 R/W|
|
||||
* +-+-+-+-+--+--+--+---+ (CC2650's I2C could read and write in the same time)
|
||||
* ps.CC2650 I2C parameter: -> U503(PB) get GPIO | U505(PA) get GPIO
|
||||
* I2C_addr = 0b 0 1 0 0 A2 A1 A0 -> 0b0100011 = [23h] | 0b0100110 = [26h]
|
||||
* tx = Register Address -> [09h] | [09h]
|
||||
* txlen=1
|
||||
* rxlen=1
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include "app_config.h"
|
||||
|
||||
#if(!CC2650_CODE)
|
||||
#include "nrf_log.h"
|
||||
#include "nrf_log_ctrl.h"
|
||||
#include "nrf_log_default_backends.h"
|
||||
#endif
|
||||
|
||||
//i2c addr
|
||||
/************************************************************************************************
|
||||
* .h
|
||||
************************************************************************************************/
|
||||
|
||||
#define GET_INPUT_SW_SEN() ((chip_MCP23008_rd_reg_stat(MCP23008_PB, MCP23008_REG_GPIO) & 0x40) >> 6)
|
||||
|
||||
#define PUSH_KEY (GET_INPUT_SW_SEN() == 0)
|
||||
|
||||
#define SET_VLOGIC_EN_GPIO(_v) (chip_MCP23008_set(MCP23008_PB, MCP23008_REG_GPIO, MCP23008_P4, _v))
|
||||
#define SET_VLOGIC_EN_IODIR(_v) (chip_MCP23008_set(MCP23008_PB, MCP23008_REG_IODIR, MCP23008_P4, _v))
|
||||
#define SET_SW_EN_GPIO(_v) (chip_MCP23008_set(MCP23008_PB, MCP23008_REG_GPIO, MCP23008_P5, _v))
|
||||
|
||||
enum mcp23008_module_e {
|
||||
MCP23008_PA = 0,
|
||||
MCP23008_PB,
|
||||
|
||||
MCP23008_MODULE_MAX,
|
||||
};
|
||||
#define PA_MODULE_I2C_ADDR 0x26
|
||||
#define PB_MODULE_I2C_ADDR 0x23
|
||||
|
||||
enum mcp23008_reg_name_e {
|
||||
MCP23008_REG_IODIR = 0x00, /*IODIR – I/O DIRECTION REGISTER (ADDR 0x00)*/
|
||||
@@ -41,35 +67,468 @@ enum mcp23008_reg_name_e {
|
||||
MCP23008_REG_MAX,
|
||||
};
|
||||
|
||||
enum mcp23008_gpio_e {
|
||||
MCP23008_P0 = 0,
|
||||
MCP23008_P1,
|
||||
MCP23008_P2,
|
||||
MCP23008_P3,
|
||||
MCP23008_P4,
|
||||
MCP23008_P5,
|
||||
MCP23008_P6,
|
||||
MCP23008_P7,
|
||||
|
||||
MCP23008_PIN_ALL,
|
||||
};
|
||||
|
||||
struct mcp23008_reg_name_t {
|
||||
uint8_t iodir;
|
||||
uint8_t gpio;
|
||||
};
|
||||
|
||||
struct mcp23008_set_para_t {
|
||||
enum mcp23008_module_e chip_module;
|
||||
enum mcp23008_reg_name_e reg_addr;
|
||||
uint8_t val;
|
||||
};
|
||||
struct mcp23008_reg_name_t mcp23008_pa = {0};
|
||||
struct mcp23008_reg_name_t mcp23008_pb = {0};
|
||||
|
||||
int chip_MCP23008_set(enum mcp23008_module_e i2c_module, enum mcp23008_reg_name_e reg_address, enum mcp23008_gpio_e wt_bit, uint8_t value);
|
||||
uint8_t chip_MCP23008_rd_reg_stat(enum mcp23008_module_e i2c_module, enum mcp23008_reg_name_e reg_address);
|
||||
/*
|
||||
* Write MCP23008(PA)'s GPIO or IODIR
|
||||
* - if want to set PA7~0's GPIO = 74h
|
||||
* i2c addr = [26h]
|
||||
* i2c tx = [09 74]
|
||||
* - if want to set PA7~0's IODIR = 02h (PA1 is output)
|
||||
* i2c addr = [26h]
|
||||
* i2c tx = [00 02]
|
||||
*/
|
||||
static uint8_t MCP23008_PA_write(enum mcp23008_reg_name_e reg)
|
||||
{
|
||||
uint8_t i2c_array[2] = {reg};
|
||||
|
||||
switch (reg) {
|
||||
case MCP23008_REG_IODIR:
|
||||
i2c_array[1] = mcp23008_pa.iodir;
|
||||
break;
|
||||
|
||||
case MCP23008_REG_GPIO:
|
||||
i2c_array[1] = mcp23008_pa.gpio;
|
||||
break;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if(CC2650_CODE)
|
||||
i2c0_write(I2C_BITRATE_400K, PA_MODULE_I2C_ADDR, i2c_array, sizeof(i2c_array));
|
||||
#else
|
||||
NRF_LOG_INFO("MCP23008_PA_write addr(%02x)", PA_MODULE_I2C_ADDR);
|
||||
NRF_LOG_HEXDUMP_INFO(i2c_array, sizeof(i2c_array));
|
||||
switch (reg) {
|
||||
case MCP23008_REG_IODIR:
|
||||
i2c_array[0] = mcp23008_pa.iodir;
|
||||
break;
|
||||
|
||||
case MCP23008_REG_GPIO:
|
||||
i2c_array[0] = mcp23008_pa.gpio;
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
|
||||
return i2c_array[0];
|
||||
}
|
||||
|
||||
/*
|
||||
* Read MCP23008(PA)'s GPIO or IODIR
|
||||
* - if want to get PA7~0's GPIO status
|
||||
* i2c addr = [26h]
|
||||
* i2c tx = [09]
|
||||
* - if want to set PA7~0's IODIR status
|
||||
* i2c addr = [26h]
|
||||
* i2c tx = [00]
|
||||
*/
|
||||
static uint8_t MCP23008_PA_read(enum mcp23008_reg_name_e reg)
|
||||
{
|
||||
uint8_t i2c_array[1] = {reg};
|
||||
|
||||
#if(CC2650_CODE)
|
||||
i2c0_write(I2C_BITRATE_400K, PA_MODULE_I2C_ADDR, i2c_array, sizeof(i2c_array));
|
||||
#else
|
||||
NRF_LOG_INFO("MCP23008_PA_read addr(%02x)", PA_MODULE_I2C_ADDR);
|
||||
NRF_LOG_HEXDUMP_INFO(i2c_array, sizeof(i2c_array));
|
||||
switch (reg) {
|
||||
case MCP23008_REG_IODIR:
|
||||
i2c_array[0] = mcp23008_pa.iodir;
|
||||
break;
|
||||
|
||||
case MCP23008_REG_GPIO:
|
||||
i2c_array[0] = mcp23008_pa.gpio;
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
|
||||
return i2c_array[0];
|
||||
}
|
||||
|
||||
/*
|
||||
* Write MCP23008(PB)'s GPIO or IODIR
|
||||
* - if want to set PB7~0's GPIO = 01h
|
||||
* i2c addr = [23h]
|
||||
* i2c tx = [09 01]
|
||||
* - if want to set PB7~0's IODIR = 08h (PB3 is output)
|
||||
* i2c addr = [23h]
|
||||
* i2c tx = [00 08]
|
||||
*/
|
||||
static uint8_t MCP23008_PB_write(enum mcp23008_reg_name_e reg)
|
||||
{
|
||||
uint8_t i2c_array[2] = {reg};
|
||||
|
||||
switch (reg) {
|
||||
case MCP23008_REG_IODIR:
|
||||
i2c_array[1] = mcp23008_pb.iodir;
|
||||
break;
|
||||
|
||||
case MCP23008_REG_GPIO:
|
||||
i2c_array[1] = mcp23008_pb.gpio;
|
||||
break;
|
||||
}
|
||||
|
||||
#if(CC2650_CODE)
|
||||
i2c0_write(I2C_BITRATE_400K, PB_MODULE_I2C_ADDR, i2c_array, sizeof(i2c_array));
|
||||
#else
|
||||
NRF_LOG_INFO("MCP23008_PB_write addr(%02x)", PB_MODULE_I2C_ADDR);
|
||||
NRF_LOG_HEXDUMP_INFO(i2c_array, sizeof(i2c_array));
|
||||
switch (reg) {
|
||||
case MCP23008_REG_IODIR:
|
||||
i2c_array[0] = mcp23008_pb.iodir;
|
||||
break;
|
||||
|
||||
case MCP23008_REG_GPIO:
|
||||
mcp23008_pb.gpio &= ~(1 << 6);
|
||||
i2c_array[0] = mcp23008_pb.gpio;
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
|
||||
return i2c_array[0];
|
||||
}
|
||||
|
||||
/*
|
||||
* Read MCP23008(PB)'s GPIO or IODIR
|
||||
* - if want to get PB7~0's GPIO status
|
||||
* i2c addr = [23h]
|
||||
* i2c tx = [09]
|
||||
* - if want to set PB7~0's IODIR status
|
||||
* i2c addr = [23h]
|
||||
* i2c tx = [00]
|
||||
*/
|
||||
static uint8_t MCP23008_PB_read(enum mcp23008_reg_name_e reg)
|
||||
{
|
||||
uint8_t i2c_array[1] = {reg};
|
||||
|
||||
#if(CC2650_CODE)
|
||||
i2c0_write(I2C_BITRATE_400K, PB_MODULE_I2C_ADDR, i2c_array, sizeof(i2c_array));
|
||||
#else
|
||||
NRF_LOG_INFO("MCP23008_PB_read addr(%02x)", PB_MODULE_I2C_ADDR);
|
||||
NRF_LOG_HEXDUMP_INFO(i2c_array, sizeof(i2c_array));
|
||||
switch (reg) {
|
||||
case MCP23008_REG_IODIR:
|
||||
i2c_array[0] = mcp23008_pa.iodir;
|
||||
break;
|
||||
|
||||
case MCP23008_REG_GPIO:
|
||||
i2c_array[0] = mcp23008_pa.gpio;
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
|
||||
return i2c_array[0];
|
||||
}
|
||||
|
||||
/**
|
||||
@brief Get MCP23008 PA's register value:[IODIR、GPIO]
|
||||
@param reg_value[2] reg_value[0] = P7-P0 IODIR
|
||||
reg_value[1] = P7-P0 GPIO
|
||||
*/
|
||||
static void get_MCP23008_PA_reg_value(uint8_t *reg_value)
|
||||
{
|
||||
reg_value[0] = MCP23008_PA_read(MCP23008_REG_IODIR);
|
||||
reg_value[1] = MCP23008_PA_read(MCP23008_REG_GPIO);
|
||||
}
|
||||
|
||||
/**
|
||||
@brief Get MCP23008 PB's register value:[IODIR、GPIO]
|
||||
@param reg_value[2] reg_value[0] = P7-P0 IODIR
|
||||
reg_value[1] = P7-P0 GPIO
|
||||
*/
|
||||
static void get_MCP23008_PB_reg_value(uint8_t *reg_value)
|
||||
{
|
||||
reg_value[0] = MCP23008_PB_read(MCP23008_REG_IODIR);
|
||||
reg_value[1] = MCP23008_PB_read(MCP23008_REG_GPIO);
|
||||
}
|
||||
|
||||
/**
|
||||
@brief Set MCP23008 to default value:
|
||||
@brief - SW_EN、APHP_EN、/WP、OSWPIN3、OSWHN、SWRST are high, other is low
|
||||
@brief - SW_SEN、Vlogic_EN、INT9466 are input, other is output
|
||||
*/
|
||||
void MCP23008_to_default(void)
|
||||
{
|
||||
mcp23008_pb.gpio = 0b00100010; //SW_EN、APHP_EN high
|
||||
MCP23008_PB_write(MCP23008_REG_GPIO);
|
||||
|
||||
mcp23008_pb.iodir = 0b01011000; //SW_SEN、Vlogic_EN、INT9466 input
|
||||
MCP23008_PB_write(MCP23008_REG_IODIR);
|
||||
|
||||
mcp23008_pa.gpio = 0b01110100; // /WP、OSWPIN3、OSWHN、SWRST high
|
||||
MCP23008_PA_write(MCP23008_REG_GPIO);
|
||||
|
||||
mcp23008_pa.iodir = 0b00000000; //all output
|
||||
MCP23008_PA_write(MCP23008_REG_IODIR);
|
||||
}
|
||||
|
||||
|
||||
/********************** get PA GPIO **********************/
|
||||
#define dioPA7 7
|
||||
#define dioPA6 6
|
||||
#define dioPA5 5
|
||||
#define dioPA4 4
|
||||
#define dioPA3 3
|
||||
#define dioPA2 2
|
||||
#define dioPA1 1
|
||||
#define dioPA0 0
|
||||
void set_pin_SWRST(bool boolflag)
|
||||
{
|
||||
if ((mcp23008_pa.gpio & 1 << dioPA2) >> dioPA2 == boolflag) {
|
||||
#if(!CC2650_CODE)
|
||||
NRF_LOG_INFO("set_pin_SWRST_PA2 same signal(%d)", boolflag);
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
|
||||
#if(!CC2650_CODE)
|
||||
NRF_LOG_INFO("set_pin_SWRST_PA2(%d)", boolflag);
|
||||
#endif
|
||||
mcp23008_pa.gpio &= ~(1 << dioPA2);
|
||||
mcp23008_pa.gpio |= boolflag << dioPA2;
|
||||
MCP23008_PA_write(MCP23008_REG_GPIO);
|
||||
}
|
||||
|
||||
void set_pin_OSWHP(bool boolflag)
|
||||
{
|
||||
if ((mcp23008_pa.gpio & 1 << dioPA3) >> dioPA3 == boolflag) {
|
||||
#if(!CC2650_CODE)
|
||||
NRF_LOG_INFO("set_pin_OSWHP_PA3 same signal(%d)", boolflag);
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
#if(!CC2650_CODE)
|
||||
NRF_LOG_INFO("set_pin_OSWHP_PA3(%d)", boolflag);
|
||||
#endif
|
||||
mcp23008_pa.gpio &= ~(1 << dioPA3);
|
||||
mcp23008_pa.gpio |= boolflag << dioPA3;
|
||||
MCP23008_PA_write(MCP23008_REG_GPIO);
|
||||
}
|
||||
|
||||
void set_pin_OSWHN(bool boolflag)
|
||||
{
|
||||
if ((mcp23008_pa.gpio & 1 << dioPA4) >> dioPA4 == boolflag) {
|
||||
#if(!CC2650_CODE)
|
||||
NRF_LOG_INFO("set_pin_OSWHN_PA4 same signal(%d)", boolflag);
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
#if(!CC2650_CODE)
|
||||
NRF_LOG_INFO("set_pin_OSWHN_PA4(%d)", boolflag);
|
||||
#endif
|
||||
mcp23008_pa.gpio &= ~(1<<dioPA4);
|
||||
mcp23008_pa.gpio |= boolflag << dioPA4;
|
||||
MCP23008_PA_write(MCP23008_REG_GPIO);
|
||||
}
|
||||
|
||||
void set_pin_OSWPIN3(bool boolflag)
|
||||
{
|
||||
if ((mcp23008_pa.gpio & 1 << dioPA5) >> dioPA5 == boolflag) {
|
||||
#if(!CC2650_CODE)
|
||||
NRF_LOG_INFO("set_pin_OSWPIN3_PA5 same signal(%d)", boolflag);
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
#if(!CC2650_CODE)
|
||||
NRF_LOG_INFO("set_pin_OSWPIN3_PA5(%d)", boolflag);
|
||||
#endif
|
||||
mcp23008_pa.gpio &= ~(1 << dioPA5);
|
||||
mcp23008_pa.gpio |= boolflag << dioPA5;
|
||||
MCP23008_PA_write(MCP23008_REG_GPIO);
|
||||
}
|
||||
|
||||
void set_pin_WP(bool boolflag)
|
||||
{
|
||||
if ((mcp23008_pa.gpio & 1 << dioPA6) >> dioPA6 == boolflag) {
|
||||
#if(!CC2650_CODE)
|
||||
NRF_LOG_INFO("set_pin_WP_PA6 same signal(%d)", boolflag);
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
#if(!CC2650_CODE)
|
||||
NRF_LOG_INFO("set_pin_WP_PA6(%d)", boolflag);
|
||||
#endif
|
||||
mcp23008_pa.gpio &= ~(1 << dioPA6);
|
||||
mcp23008_pa.gpio |= boolflag << dioPA6;
|
||||
MCP23008_PA_write(MCP23008_REG_GPIO);
|
||||
}
|
||||
|
||||
|
||||
/********************** get PB GPIO **********************/
|
||||
#define dioPB7 7
|
||||
#define dioPB6 6
|
||||
#define dioPB5 5
|
||||
#define dioPB4 4
|
||||
#define dioPB3 3
|
||||
#define dioPB2 2
|
||||
#define dioPB1 1
|
||||
#define dioPB0 0
|
||||
void set_pin_APHP_EN(bool boolflag)
|
||||
{
|
||||
if ((mcp23008_pb.gpio & 1 << dioPB0) >> dioPB0 == boolflag) {
|
||||
#if(!CC2650_CODE)
|
||||
NRF_LOG_INFO("set_pin_APHP_EN_PB0 same signal(%d)", boolflag);
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
#if(!CC2650_CODE)
|
||||
NRF_LOG_INFO("set_pin_APHP_EN_PB0(%d)", boolflag);
|
||||
#endif
|
||||
mcp23008_pb.gpio &= ~(1 << dioPB0);
|
||||
mcp23008_pb.gpio |= boolflag << dioPB0;
|
||||
MCP23008_PB_write(MCP23008_REG_GPIO);
|
||||
}
|
||||
|
||||
void set_pin_APHP_EN_neg(bool boolflag)
|
||||
{
|
||||
if ((mcp23008_pb.gpio & 1 << dioPB1) >> dioPB1 == boolflag) {
|
||||
#if(!CC2650_CODE)
|
||||
NRF_LOG_INFO("set_pin_APHP_EN_neg_PB1 same signal(%d)", boolflag);
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
#if(!CC2650_CODE)
|
||||
NRF_LOG_INFO("set_pin_APHP_EN_neg_PB1(%d)", boolflag);
|
||||
#endif
|
||||
mcp23008_pb.gpio &= ~(1 << dioPB1);
|
||||
mcp23008_pb.gpio |= boolflag << dioPB1;
|
||||
MCP23008_PB_write(MCP23008_REG_GPIO);
|
||||
}
|
||||
|
||||
void set_pin_INT9466(bool boolflag)
|
||||
{
|
||||
if ((mcp23008_pb.gpio & 1 << dioPB3) >> dioPB3 == boolflag) {
|
||||
#if(!CC2650_CODE)
|
||||
NRF_LOG_INFO("set_pin_INT9466_PB3 same signal(%d)", boolflag);
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
#if(!CC2650_CODE)
|
||||
NRF_LOG_INFO("set_pin_INT9466_PB3(%d)", boolflag);
|
||||
#endif
|
||||
mcp23008_pb.gpio &= ~(1 << dioPB3);
|
||||
mcp23008_pb.gpio |= boolflag << dioPB3;
|
||||
MCP23008_PB_write(MCP23008_REG_GPIO);
|
||||
}
|
||||
|
||||
void set_pin_Vlogic_EN(bool boolflag) // 'Vlogic_EN' or 'Power_EN'
|
||||
{
|
||||
if ((mcp23008_pb.gpio & 1 << dioPB4) >> dioPB4 == boolflag) {
|
||||
#if(!CC2650_CODE)
|
||||
NRF_LOG_INFO("set_pin_Vlogic_EN_PB4 same signal(%d)", boolflag);
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
#if(!CC2650_CODE)
|
||||
NRF_LOG_INFO("set_pin_Vlogic_EN_PB4(%d)", boolflag);
|
||||
#endif
|
||||
mcp23008_pb.gpio &= ~(1 << dioPB4);
|
||||
mcp23008_pb.gpio |= boolflag << dioPB4;
|
||||
MCP23008_PB_write(MCP23008_REG_GPIO);
|
||||
}
|
||||
|
||||
void set_pin_SW_EN(bool boolflag)
|
||||
{
|
||||
if ((mcp23008_pb.gpio & 1 << dioPB5) >> dioPB5 == boolflag) {
|
||||
#if(!CC2650_CODE)
|
||||
NRF_LOG_INFO("set_pin_SW_EN_PB5 same signal(%d)", boolflag);
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
#if(!CC2650_CODE)
|
||||
NRF_LOG_INFO("set_pin_SW_EN_PB5(%d)", boolflag);
|
||||
#endif
|
||||
mcp23008_pb.gpio &= ~(1 << dioPB5);
|
||||
mcp23008_pb.gpio |= boolflag << dioPB5;
|
||||
MCP23008_PB_write(MCP23008_REG_GPIO);
|
||||
}
|
||||
|
||||
void set_pin_SW_SEN(bool boolflag)
|
||||
{
|
||||
if ((mcp23008_pb.gpio & 1 << dioPB6) >> dioPB6 == boolflag) {
|
||||
#if(!CC2650_CODE)
|
||||
NRF_LOG_INFO("set_pin_SW_SEN_PB6 same signal(%d)", boolflag);
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
#if(!CC2650_CODE)
|
||||
NRF_LOG_INFO("set_pin_SW_SEN_PB6(%d)", boolflag);
|
||||
#endif
|
||||
mcp23008_pb.gpio &= ~(1 << dioPB6);
|
||||
mcp23008_pb.gpio |= boolflag << dioPB6;
|
||||
MCP23008_PB_write(MCP23008_REG_GPIO);
|
||||
}
|
||||
|
||||
void set_pin_Shutdown(bool boolflag) // 'Shutdown' or 'shut_down'
|
||||
{
|
||||
if ((mcp23008_pb.gpio & 1 << dioPB7) >> dioPB7 == boolflag) {
|
||||
#if(!CC2650_CODE)
|
||||
NRF_LOG_INFO("set_pin_Shutdown_PB7 same signal(%d)", boolflag);
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
#if(!CC2650_CODE)
|
||||
NRF_LOG_INFO("set_pin_Shutdown_PB7(%d)", boolflag);
|
||||
#endif
|
||||
mcp23008_pb.gpio &= ~(1 << dioPB7);
|
||||
mcp23008_pb.gpio |= boolflag << dioPB7;
|
||||
MCP23008_PB_write(MCP23008_REG_GPIO);
|
||||
}
|
||||
|
||||
|
||||
/********************** get GPIO **********************/
|
||||
bool get_pin_SW_SEN(void)
|
||||
{
|
||||
uint8_t gpio_reg_value;
|
||||
|
||||
#if(!CC2650_CODE)
|
||||
NRF_LOG_INFO("get_pin_SW_SEN");
|
||||
#endif
|
||||
gpio_reg_value = MCP23008_PB_read(MCP23008_REG_GPIO);
|
||||
#if(!CC2650_CODE)
|
||||
NRF_LOG_INFO("SW_SEN=(%d)", (gpio_reg_value & 1 << dioPB6) >> dioPB6);
|
||||
#endif
|
||||
|
||||
return (gpio_reg_value & 1 << dioPB6) >> dioPB6;
|
||||
}
|
||||
|
||||
bool get_pin_INT9466(void)
|
||||
{
|
||||
uint8_t gpio_reg_value;
|
||||
|
||||
#if(!CC2650_CODE)
|
||||
NRF_LOG_INFO("get_pin_INT9466")
|
||||
#endif
|
||||
gpio_reg_value = MCP23008_PB_read(MCP23008_REG_GPIO);
|
||||
#if(!CC2650_CODE)
|
||||
NRF_LOG_INFO("INT9466=(%d)", (gpio_reg_value & 1 << dioPB3) >> dioPB3);
|
||||
#endif
|
||||
|
||||
return (gpio_reg_value & 1 << dioPB3) >> dioPB3;
|
||||
}
|
||||
|
||||
|
||||
/********************** get IODIR **********************/
|
||||
/**
|
||||
@brief Set IODIR of Vlogic_EN pin. ['Vlogic_EN' or 'Power_EN']
|
||||
@param in_out_flag SET_OUTPUT / SET_INPUT
|
||||
*/
|
||||
void set_pin_Vlogic_EN_iodir(uint8_t in_out_flag)
|
||||
{
|
||||
if ((mcp23008_pb.iodir & 1 << dioPB4) >> dioPB4 == in_out_flag) {
|
||||
#if(!CC2650_CODE)
|
||||
NRF_LOG_INFO("set_pin_Vlogic_EN_iodir same signal(%d)", in_out_flag);
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
#if(!CC2650_CODE)
|
||||
NRF_LOG_INFO("set_pin_Vlogic_EN_iodir(%d)", in_out_flag);
|
||||
#endif
|
||||
mcp23008_pb.iodir &= ~(1 << dioPB4);
|
||||
mcp23008_pb.iodir |= in_out_flag << dioPB4;
|
||||
MCP23008_PB_write(MCP23008_REG_IODIR);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -1,205 +0,0 @@
|
||||
/*
|
||||
* MCP23008: Series data structure
|
||||
* I2C
|
||||
* -Write:
|
||||
* +---------------------+------------------------+-------------+
|
||||
* | Device Opcode(1B) | Register Address(1B) | Value(1B) |
|
||||
* +---------------------+------------------------+-------------+
|
||||
* / \
|
||||
* / Device Opcode(1B)\
|
||||
* / \
|
||||
* 0 1 2 3 4 5 6 7
|
||||
* +-+-+-+-+--+--+--+---+
|
||||
* | 0100 |A2 A1 A0 R/W|
|
||||
* +-+-+-+-+--+--+--+---+
|
||||
* ps.CC2650 I2C parameter:I2C_addr、tx、txlen、rxlen,
|
||||
* I2C_addr = 0b 0 1 0 0 A2 A1 A0
|
||||
* tx = Register Address + Value
|
||||
* txlen=2
|
||||
* rxlen=1
|
||||
*
|
||||
*
|
||||
* -Read:
|
||||
* +---------------------+------------------------+
|
||||
* | Device Opcode(1B) | Register Address(1B) |
|
||||
* +---------------------+------------------------+
|
||||
* / \
|
||||
* / Device Opcode(1B)\
|
||||
* / \
|
||||
* 0 1 2 3 4 5 6 7
|
||||
* +-+-+-+-+--+--+--+---+
|
||||
* | 0100 |A2 A1 A0 R/W|
|
||||
* +-+-+-+-+--+--+--+---+
|
||||
* ps.CC2650 I2C parameter:I2C_addr、tx、txlen、rxlen,
|
||||
* I2C_addr = 0b 0 1 0 0 A2 A1 A0
|
||||
* tx = Register Address
|
||||
* txlen=1
|
||||
* rxlen=1
|
||||
*
|
||||
*/
|
||||
|
||||
#include "HAL/MCP23008x2.h"
|
||||
#include "HAL/cc2650_driver/i2c_ctrl.h"
|
||||
|
||||
#define MCP23008_WT_BIT 0
|
||||
#define MCP23008_RD_BIT 1
|
||||
|
||||
static uint8_t module_addr_g[MCP23008_MODULE_MAX] = {
|
||||
0x4C, // MCP23008_PA
|
||||
0x46, // MCP23008_PB
|
||||
};
|
||||
|
||||
static struct mcp23008_reg_name_t mcp23008_reg_name_g[MCP23008_MODULE_MAX] = {0};
|
||||
|
||||
static uint8_t __mcp23008_reg_value_get(struct mcp23008_set_para_t *mcp23008_ctrl_para)
|
||||
{
|
||||
struct mcp23008_set_para_t *para = mcp23008_ctrl_para;
|
||||
struct mcp23008_reg_name_t *p;
|
||||
uint8_t ret;
|
||||
|
||||
p = mcp23008_reg_name_g + para->chip_module;
|
||||
|
||||
switch(para->reg_addr) {
|
||||
case MCP23008_REG_GPIO:
|
||||
ret = p->gpio;
|
||||
break;
|
||||
|
||||
case MCP23008_REG_IODIR:
|
||||
ret = p->iodir;
|
||||
break;
|
||||
|
||||
default:
|
||||
ret = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
static void __mcp23008_reg_value_set(struct mcp23008_set_para_t *mcp23008_ctrl_para)
|
||||
{
|
||||
struct mcp23008_set_para_t *para = mcp23008_ctrl_para;
|
||||
struct mcp23008_reg_name_t *p;
|
||||
|
||||
p = mcp23008_reg_name_g + para->chip_module;
|
||||
|
||||
switch(para->reg_addr) {
|
||||
case MCP23008_REG_GPIO:
|
||||
p->gpio = para->val;
|
||||
break;
|
||||
|
||||
case MCP23008_REG_IODIR:
|
||||
p->iodir = para->val;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
static int __chip_MCP23008_i2c_write(struct mcp23008_set_para_t *mcp23008_ctrl_para)
|
||||
{
|
||||
struct mcp23008_set_para_t *para = mcp23008_ctrl_para;
|
||||
struct i2c_para_t i2c_send;
|
||||
struct i2c_para_t *send = &i2c_send;
|
||||
int ret;
|
||||
|
||||
send->i2c_txlen = 2;
|
||||
send->i2c_rxlen = 1;
|
||||
send->i2c_addr = module_addr_g[para->chip_module] | MCP23008_WT_BIT;
|
||||
memcpy(send->i2c_tx, ¶->reg_addr, 1);
|
||||
memcpy(&send->i2c_tx[1], ¶->val, 1);
|
||||
|
||||
ret = i2c0_write(send);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static uint8_t __chip_MCP23008_i2c_read(struct mcp23008_set_para_t *mcp23008_ctrl_para)
|
||||
{
|
||||
struct mcp23008_set_para_t *para = mcp23008_ctrl_para;
|
||||
struct i2c_para_t i2c_read;
|
||||
struct i2c_para_t *read = &i2c_read;
|
||||
|
||||
read->i2c_txlen = 1;
|
||||
read->i2c_rxlen = 1;
|
||||
read->i2c_addr = module_addr_g[para->chip_module] | MCP23008_RD_BIT;
|
||||
memcpy(read->i2c_tx, ¶->reg_addr, 1);
|
||||
|
||||
if (i2c0_write(read) == 0) {
|
||||
para->val = read->i2c_rx[0];
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
int chip_MCP23008_set(enum mcp23008_module_e i2c_module, enum mcp23008_reg_name_e reg_address, enum mcp23008_gpio_e wt_bit, uint8_t value)
|
||||
{
|
||||
struct mcp23008_set_para_t mcp23008_ctrl_para;
|
||||
struct mcp23008_set_para_t *para = &mcp23008_ctrl_para;
|
||||
enum mcp23008_module_e modul = i2c_module;
|
||||
enum mcp23008_reg_name_e reg = reg_address; // for current version, it selects IODIR or GPIO
|
||||
enum mcp23008_gpio_e wt_b = wt_bit; //
|
||||
uint8_t v = value;
|
||||
uint8_t set_val = 0;
|
||||
|
||||
if (modul >= MCP23008_MODULE_MAX)
|
||||
return -1;
|
||||
|
||||
if (reg >= MCP23008_REG_MAX)
|
||||
return -2;
|
||||
|
||||
if (wt_b > MCP23008_PIN_ALL)
|
||||
return -3;
|
||||
|
||||
if (wt_b < MCP23008_PIN_ALL && v > 1)
|
||||
return -4;
|
||||
|
||||
para->chip_module = modul;
|
||||
para->reg_addr = reg;
|
||||
para->val = v;
|
||||
|
||||
if (wt_b < MCP23008_PIN_ALL) {
|
||||
set_val = __mcp23008_reg_value_get(para);
|
||||
set_val &= ~(1 << wt_b);
|
||||
set_val |= v << wt_b;
|
||||
para->val = set_val;
|
||||
}
|
||||
|
||||
if (__chip_MCP23008_i2c_write(para) == 0) {
|
||||
__mcp23008_reg_value_set(para);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
uint8_t chip_MCP23008_rd_reg_stat(enum mcp23008_module_e i2c_module, enum mcp23008_reg_name_e reg_address)
|
||||
{
|
||||
struct mcp23008_set_para_t mcp23008_ctrl_para;
|
||||
struct mcp23008_set_para_t *para = &mcp23008_ctrl_para;
|
||||
enum mcp23008_module_e modul = i2c_module;
|
||||
enum mcp23008_reg_name_e reg = reg_address;
|
||||
|
||||
if (modul >= MCP23008_MODULE_MAX)
|
||||
return 0;
|
||||
|
||||
if (reg >= MCP23008_REG_MAX)
|
||||
return 0;
|
||||
|
||||
para->chip_module = modul;
|
||||
para->reg_addr = reg;
|
||||
|
||||
__chip_MCP23008_i2c_read(para);
|
||||
|
||||
return para->val;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,138 @@
|
||||
#include <stdint.h>
|
||||
#include <math.h>
|
||||
#include "app_config.h"
|
||||
|
||||
#if(!CC2650_CODE)
|
||||
#include "nrf_log.h"
|
||||
#include "nrf_log_ctrl.h"
|
||||
#include "nrf_log_default_backends.h"
|
||||
#endif
|
||||
|
||||
#define U303_MODULE_I2C_ADDR 0x3C
|
||||
#define U304_MODULE_I2C_ADDR 0x3D
|
||||
|
||||
#define DEVICE_MEMORY_ADDR_WIPER0 0x00
|
||||
#define DEVICE_MEMORY_ADDR_TCON 0x04
|
||||
|
||||
#define CMD_WRITE_DATA 0x00
|
||||
#define CMD_INCREMENT 0x01
|
||||
#define CMD_DECREMENT 0x10
|
||||
#define CMD_READ_DATA 0x11
|
||||
|
||||
/**
|
||||
@brief Write MCP45HV51(U303)
|
||||
@param device_memory_addr DEVICE_MEMORY_ADDR_WIPER0 / DEVICE_MEMORY_ADDR_TCON
|
||||
@param rw_command CMD_WRITE_DATA / CMD_INCREMENT / CMD_DECREMENT / CMD_READ_DATA
|
||||
@param data 0x00~0xFF
|
||||
*/
|
||||
static uint8_t MCP45HV51_i2c_write_sequence(uint8_t i2c_addr, uint8_t device_memory_addr, uint8_t rw_command, uint8_t data)
|
||||
{
|
||||
uint8_t i2c_array[2] = {0};
|
||||
|
||||
i2c_array[0] = device_memory_addr<<4 | rw_command<<2;
|
||||
i2c_array[1] = data;
|
||||
|
||||
#if(CC2650_CODE)
|
||||
i2c0_write(I2C_BITRATE_400K, i2c_addr, i2c_array, sizeof(i2c_array));
|
||||
#else
|
||||
NRF_LOG_INFO("MCP45HV51_i2c_write_sequence addr(%02x)", i2c_addr);
|
||||
NRF_LOG_HEXDUMP_INFO(i2c_array, sizeof(i2c_array));
|
||||
#endif
|
||||
|
||||
return i2c_array[0];
|
||||
}
|
||||
|
||||
/**
|
||||
@brief Set +SW voltage
|
||||
@param uv 800000 ~ 14133333uV
|
||||
U303:
|
||||
if data = FFh
|
||||
- POW~POB's resistance = data * 50000 / 255 [POW~POB resistance = 0K~50K]
|
||||
POW~POB's resistance = 50000 = 50Kohm
|
||||
- vout = 0.8 * (POW~POB's resistance / 3Kohm + 1)
|
||||
vout = 0.8 * (50000 / 3000 + 1)
|
||||
vout = 14.133333V
|
||||
So if want to get 10V:
|
||||
- POW~POB's resistance = (10*1e6[uV] / 0.8 - 1*1e6) / 1e6 * 3000 = 34500ohm
|
||||
- data = 34500 * 255 / 50000 = 175.95 -> 176
|
||||
*/
|
||||
void set_SW_P_voltage(int32_t uv)
|
||||
{
|
||||
#if(!CC2650_CODE)
|
||||
NRF_LOG_INFO("set_SW_P_voltage(%d)", uv);
|
||||
#endif
|
||||
|
||||
if (uv <= 800000) {
|
||||
uv = 800000;
|
||||
} else if (uv >= 14133333) {
|
||||
uv = 14133333;
|
||||
}
|
||||
|
||||
uint8_t rx;
|
||||
int64_t value;
|
||||
double temp = (uv / 0.8 - 1e6) * 153 / 1e7;
|
||||
|
||||
if (fmod(temp, 1.0) == 0.0) {
|
||||
value = (int64_t)temp;
|
||||
} else {
|
||||
value = (int64_t)ceil(temp);
|
||||
}
|
||||
|
||||
rx = MCP45HV51_i2c_write_sequence(U303_MODULE_I2C_ADDR, DEVICE_MEMORY_ADDR_WIPER0, CMD_WRITE_DATA, (uint8_t)value);
|
||||
|
||||
#if(CC2650_CODE)
|
||||
uint8_t ack_buf[20] = {0};
|
||||
ack_buf[0] = 2; //data len
|
||||
ack_buf[1] = 0xB0;
|
||||
ack_buf[2] = rx;
|
||||
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, BLE_CIS_BUFF_SIZE, ack_buf);
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
@brief Set -SW voltage
|
||||
@param uv -600000 ~ -14236363uV
|
||||
U304:
|
||||
if data = FFh
|
||||
- POW~POB's resistance = data * 50000 / 255 [POW~POB resistance = 0K~50K]
|
||||
POW~POB's resistance = 50000 = 50Kohm
|
||||
- vout = (POW~POB's resistance * 0.6 / 2.2Kohm + 0.6)
|
||||
vout = (50000 * 0.6 / 2200 + 0.6)
|
||||
vout = 14.236363V (negative voltage)
|
||||
So if want to get 10V(negative voltage):
|
||||
- POW~POB's resistance = (10*1e6[uV] - 0.6*1e6) * 2200 / 0.6 / 1e6 = 34466ohm
|
||||
- data = 34466 * 255 / 50000 = 175.77 -> 176
|
||||
*/
|
||||
void set_SW_N_voltage(int32_t uv)
|
||||
{
|
||||
#if(!CC2650_CODE)
|
||||
NRF_LOG_INFO("set_SW_N_voltage(%d)", uv);
|
||||
#endif
|
||||
|
||||
uv = uv * (-1);
|
||||
if (uv <= 600000) {
|
||||
uv = 600000;
|
||||
} else if (uv >= 14236363) {
|
||||
uv = 14236363;
|
||||
}
|
||||
|
||||
uint8_t rx;
|
||||
int64_t value;
|
||||
double temp = (uv - 6*1e5) * 187 / 1e7;
|
||||
|
||||
if (fmod(temp, 1.0) == 0.0) {
|
||||
value = (int64_t)temp;
|
||||
} else {
|
||||
value = (int64_t)ceil(temp);
|
||||
}
|
||||
|
||||
rx = MCP45HV51_i2c_write_sequence(U304_MODULE_I2C_ADDR, DEVICE_MEMORY_ADDR_WIPER0, CMD_WRITE_DATA, (uint8_t)value);
|
||||
|
||||
#if(CC2650_CODE)
|
||||
uint8_t ack_buf[20] = {0};
|
||||
ack_buf[0] = 2; //data len
|
||||
ack_buf[1] = 0xB0;
|
||||
ack_buf[2] = rx;
|
||||
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, BLE_CIS_BUFF_SIZE, ack_buf);
|
||||
#endif
|
||||
}
|
||||
@@ -0,0 +1,173 @@
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include "app_config.h"
|
||||
|
||||
#if(!CC2650_CODE)
|
||||
#include "nrf_log.h"
|
||||
#include "nrf_log_ctrl.h"
|
||||
#include "nrf_log_default_backends.h"
|
||||
#else
|
||||
#include <ti/drivers/pin/PINCC26XX.h>
|
||||
#include <ti/drivers/PIN.h>
|
||||
#include <ti/drivers/I2C.h>
|
||||
#include "Board.h" // src\boards\BOOSTXL_CC2650MA\Board.h
|
||||
#endif
|
||||
|
||||
/********************************** GPIO **********************************/
|
||||
//Assign Elite other pins
|
||||
#define E_PIN_ADCA0 DIO0
|
||||
#define E_PIN_ADCA1 DIO1
|
||||
#define E_PIN_ADCA2 DIO7
|
||||
#define E_PIN_SWCSBB DIO2
|
||||
#define E_PIN_MEMCS DIO3
|
||||
#define E_PIN_DACCS DIO10
|
||||
#define E_PIN_ADCCS DIO11
|
||||
|
||||
#if(CC2650_CODE)
|
||||
PIN_Handle Elite_pin_handle;
|
||||
PIN_State Elite_state;
|
||||
|
||||
void elite_pin_create(void)
|
||||
{
|
||||
const PIN_Config elite_pin_table[] = {
|
||||
E_PIN_ADCA0 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX,
|
||||
E_PIN_ADCA1 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX,
|
||||
E_PIN_ADCA2 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX,
|
||||
E_PIN_SWCSBB | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL | PIN_DRVSTR_MAX,
|
||||
E_PIN_MEMCS | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL | PIN_DRVSTR_MAX,
|
||||
E_PIN_ADCCS | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL | PIN_DRVSTR_MAX,
|
||||
E_PIN_DACCS | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL | PIN_DRVSTR_MAX,
|
||||
|
||||
PIN_TERMINATE
|
||||
};
|
||||
|
||||
Elite_pin_handle = PIN_open(&Elite_state, elite_pin_table);
|
||||
}
|
||||
#endif
|
||||
|
||||
void set_pin_ADCA0(bool boolflag)
|
||||
{
|
||||
#if(CC2650_CODE)
|
||||
PIN_setOutputValue(Elite_pin_handle, E_PIN_ADCA0, boolflag);
|
||||
#else
|
||||
NRF_LOG_INFO("set_pin_ADCA0(%d)", boolflag);
|
||||
#endif
|
||||
}
|
||||
|
||||
void set_pin_ADCA1(bool boolflag)
|
||||
{
|
||||
#if(CC2650_CODE)
|
||||
PIN_setOutputValue(Elite_pin_handle, E_PIN_ADCA1, boolflag);
|
||||
#else
|
||||
NRF_LOG_INFO("set_pin_ADCA1(%d)", boolflag);
|
||||
#endif
|
||||
}
|
||||
|
||||
void set_pin_ADCA2(bool boolflag)
|
||||
{
|
||||
#if(CC2650_CODE)
|
||||
PIN_setOutputValue(Elite_pin_handle, E_PIN_ADCA2, boolflag);
|
||||
#else
|
||||
NRF_LOG_INFO("set_pin_ADCA2(%d)", boolflag);
|
||||
#endif
|
||||
}
|
||||
|
||||
void set_pin_ADCCS(bool boolflag)
|
||||
{
|
||||
#if(CC2650_CODE)
|
||||
PIN_setOutputValue(Elite_pin_handle, E_PIN_ADCCS, boolflag);
|
||||
#else
|
||||
NRF_LOG_INFO("set_pin_ADCCS(%d)", boolflag);
|
||||
#endif
|
||||
}
|
||||
|
||||
void set_pin_DACCS(bool boolflag)
|
||||
{
|
||||
#if(CC2650_CODE)
|
||||
PIN_setOutputValue(Elite_pin_handle, E_PIN_DACCS, boolflag);
|
||||
#else
|
||||
NRF_LOG_INFO("set_pin_DACCS(%d)", boolflag);
|
||||
#endif
|
||||
}
|
||||
|
||||
void set_pin_SWCSBB(bool boolflag)
|
||||
{
|
||||
#if(CC2650_CODE)
|
||||
PIN_setOutputValue(Elite_pin_handle, E_PIN_SWCSBB, boolflag);
|
||||
#else
|
||||
NRF_LOG_INFO("set_pin_SWCSBB(%d)", boolflag);
|
||||
#endif
|
||||
}
|
||||
|
||||
void set_pin_MEMCS(bool boolflag)
|
||||
{
|
||||
#if(CC2650_CODE)
|
||||
PIN_setOutputValue(Elite_pin_handle, E_PIN_MEMCS, boolflag);
|
||||
#else
|
||||
NRF_LOG_INFO("set_pin_MEMCS(%d)", boolflag);
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
* ADCA0: 0
|
||||
* ADCA1: 0
|
||||
* ADCA2: 0
|
||||
* ADCCS: 1
|
||||
* DACCS: 1
|
||||
* SWCSBB: 1
|
||||
* MEMCS: 1
|
||||
*/
|
||||
void set_all_pin_to_default(void)
|
||||
{
|
||||
set_pin_ADCA0(0);
|
||||
set_pin_ADCA1(0);
|
||||
set_pin_ADCA2(0);
|
||||
set_pin_ADCCS(1);
|
||||
set_pin_DACCS(1);
|
||||
set_pin_SWCSBB(1);
|
||||
set_pin_MEMCS(1);
|
||||
}
|
||||
|
||||
|
||||
/********************************** I2C **********************************/
|
||||
/**
|
||||
@brief Write i2c
|
||||
@param i2c_bit_rate I2C_BITRATE_100K / I2C_BITRATE_400K
|
||||
@param i2c_addr i2c address
|
||||
@param i2c_array send uint8_t array
|
||||
@param i2c_array_len 0~255
|
||||
*/
|
||||
bool i2c0_write(uint8_t i2c_bit_rate, uint8_t i2c_addr, uint8_t *i2c_array, uint8_t i2c_array_len)
|
||||
{
|
||||
I2C_Handle handle = NULL;
|
||||
I2C_Params para;
|
||||
I2C_BitRate bit_rate;
|
||||
I2C_Transaction trans;
|
||||
bool status;
|
||||
|
||||
if (i2c_bit_rate == I2C_BITRATE_100K)
|
||||
bit_rate = I2C_100kHz;
|
||||
else if (i2c_bit_rate == I2C_BITRATE_400K)
|
||||
bit_rate = I2C_400kHz;
|
||||
|
||||
//open I2C
|
||||
Board_initI2C();
|
||||
I2C_Params_init(¶);
|
||||
para.bitRate = bit_rate;
|
||||
handle = I2C_open(Board_I2C0, ¶);
|
||||
|
||||
//write I2C
|
||||
trans.writeCount = i2c_array_len;
|
||||
trans.writeBuf = i2c_array;
|
||||
trans.readCount = i2c_array_len;
|
||||
trans.readBuf = i2c_array;
|
||||
trans.slaveAddress = i2c_addr;
|
||||
status = I2C_transfer(handle, &trans); // status be true to indicate success, and false on an error.
|
||||
|
||||
//close I2C
|
||||
I2C_close(handle);
|
||||
handle = NULL;
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
#ifndef I2C_CTRL_H
|
||||
#define I2C_CTRL_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define I2C_100K I2C_100kHz
|
||||
#define I2C_400K I2C_400kHz
|
||||
|
||||
struct i2c_para_t {
|
||||
uint8_t i2c_addr;
|
||||
uint8_t i2c_txlen;
|
||||
uint8_t i2c_rxlen;
|
||||
uint8_t i2c_tx[256];
|
||||
uint8_t i2c_rx[256];
|
||||
};
|
||||
|
||||
int i2c0_open(uint8_t bitRate);
|
||||
int i2c0_write(struct i2c_para_t *i2c_para);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
@@ -1,46 +0,0 @@
|
||||
#include <Board.h>
|
||||
#include <ti/drivers/I2C.h>
|
||||
#include "HAL/cc2650_driver/i2c_ctrl.h"
|
||||
|
||||
/* system use I2C parameters */
|
||||
static I2C_Handle I2Chandle0 = NULL;
|
||||
static I2C_Params I2CParams0;
|
||||
|
||||
/* Open the I2C driver */
|
||||
int i2c0_open(uint8_t bitRate)
|
||||
{
|
||||
//ret=0 -> success
|
||||
// =1 -> already exists
|
||||
// =2 -> open fail
|
||||
uint8_t rate = bitRate;
|
||||
|
||||
if (I2Chandle0 != NULL)
|
||||
return 1;
|
||||
|
||||
/* Configure I2C */
|
||||
I2C_Params_init(&I2CParams0);
|
||||
I2CParams0.bitRate = rate;
|
||||
|
||||
/* Attempt to open I2C. */
|
||||
I2Chandle0 = I2C_open(Board_I2C0, &I2CParams0);
|
||||
|
||||
if (I2Chandle0 == NULL)
|
||||
return 2;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int i2c0_write(struct i2c_para_t *i2c_para)
|
||||
{
|
||||
struct i2c_para_t *p = i2c_para;
|
||||
|
||||
I2C_Transaction I2C0Transaction;
|
||||
|
||||
I2C0Transaction.writeCount = p->i2c_txlen;
|
||||
I2C0Transaction.writeBuf = p->i2c_tx;
|
||||
I2C0Transaction.readCount = p->i2c_rxlen;
|
||||
I2C0Transaction.readBuf = p->i2c_rx;
|
||||
I2C0Transaction.slaveAddress = p->i2c_addr>>1;
|
||||
|
||||
return I2C_transfer(I2Chandle0, &I2C0Transaction) ? 0 : -1;
|
||||
}
|
||||
@@ -10,6 +10,7 @@ extern "C" {
|
||||
#define PHA0 0
|
||||
#define PHA1 1
|
||||
|
||||
#define SPI_CLK_12M 12000000
|
||||
#define SPI_CLK_10M 10000000
|
||||
#define SPI_CLK_4M 4000000
|
||||
|
||||
|
||||
@@ -2,20 +2,24 @@
|
||||
#include <ti/drivers/SPI.h>
|
||||
#include "HAL/cc2650_driver/spi_ctrl.h"
|
||||
/*
|
||||
SPI bit rate in Hz.
|
||||
|
||||
Maximum bit rates supported by hardware:
|
||||
|
||||
+---------------+-----------------+------------------+
|
||||
| Device Family | Slave Max (MHz) | Master Max (MHz) |
|
||||
+---------------+-----------------+------------------+
|
||||
| MSP432P4 | 16 MHz | 24 MHz |
|
||||
| MSP432E4 | 10 MHz | 60 MHz |
|
||||
| CC13XX/CC26XX | 4 MHz | 12 MHz |
|
||||
| CC32XX | 20 MHz | 20 MHz |
|
||||
+---------------+-----------------+------------------+
|
||||
Please note that depending on the specific use case, the driver may not support the hardware's maximum bit rate.
|
||||
*/
|
||||
* Read SPI example in
|
||||
* http://software-dl.ti.com/dsps/dsps_public_sw/sdo_sb/targetcontent/tirtos/2_14_02_22/
|
||||
* exports/tirtos_full_2_14_02_22/docs/doxygen/html/_s_p_i_c_c26_x_x_d_m_a_8h.html
|
||||
*
|
||||
* SPI bit rate in Hz.
|
||||
*
|
||||
* Maximum bit rates supported by hardware:
|
||||
*
|
||||
* +---------------+-----------------+------------------+
|
||||
* | Device Family | Slave Max (MHz) | Master Max (MHz) |
|
||||
* +---------------+-----------------+------------------+
|
||||
* | MSP432P4 | 16 MHz | 24 MHz |
|
||||
* | MSP432E4 | 10 MHz | 60 MHz |
|
||||
* | CC13XX/CC26XX | 4 MHz | 12 MHz |
|
||||
* | CC32XX | 20 MHz | 20 MHz |
|
||||
* +---------------+-----------------+------------------+
|
||||
* Please note that depending on the specific use case, the driver may not support the hardware's maximum bit rate.
|
||||
*/
|
||||
|
||||
/* system use SPI parameters */
|
||||
static SPI_Handle spiHandle0 = NULL;
|
||||
@@ -35,6 +39,7 @@ int spi0_open(uint32_t bitRate, uint8_t polarity, uint8_t phase)
|
||||
uint8_t pha = phase;
|
||||
SPI_FrameFormat frameFormat;
|
||||
|
||||
|
||||
if (spiHandle0 != NULL)
|
||||
return 1;
|
||||
|
||||
@@ -48,6 +53,7 @@ int spi0_open(uint32_t bitRate, uint8_t polarity, uint8_t phase)
|
||||
frameFormat = SPI_POL1_PHA1;
|
||||
|
||||
/* Configure SPI as master */
|
||||
Board_initSPI();
|
||||
SPI_Params_init(&spiParams0);
|
||||
spiParams0.bitRate = rate;
|
||||
spiParams0.mode = SPI_MASTER;
|
||||
@@ -103,6 +109,8 @@ int spi1_open(uint32_t bitRate, uint8_t polarity, uint8_t phase)
|
||||
uint8_t pha = phase;
|
||||
SPI_FrameFormat frameFormat;
|
||||
|
||||
Board_initSPI();
|
||||
|
||||
if (spiHandle1 != NULL)
|
||||
return 1;
|
||||
|
||||
|
||||
@@ -0,0 +1,98 @@
|
||||
|
||||
#ifndef APPLICATION_CONFIG_H
|
||||
#define APPLICATION_CONFIG_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*
|
||||
*
|
||||
* product number: MAJOR_PRODUCT_NUMBER, MINOR_PRODUCT_NUMBER, MAJOR_VERSION_NUMBER, MINOR_VERSION_NUMBER
|
||||
* MAJOR_PRODUCT_NUMBER -> 0:Elite, 1:other serial
|
||||
* MINOR_PRODUCT_NUMBER(Elite) -> 1:legacy, 2:EDC, 3:BAT, 4:EIS, 5:TRIG, 6:MEGAFLY
|
||||
*
|
||||
* +------------------------+----------------------+-------------------------+----------------------+
|
||||
* | model name | hw upper board | hw lower board | device name |
|
||||
* +------------------------+----------------------+-------------------------+----------------------+
|
||||
* | DEF_ELITE_EDC_14 | Elite1.4-re Jun.2019 | Elite1.4-re Jun. 2019 | "Elite-EDC" |
|
||||
* | DEF_ELITE_EDC_15 | Elite1.5 Dec. 2019 | Elite1.5 Dec. 2019 | "Elite-EDC" |
|
||||
* | DEF_ELITE_EDC_15RE | Elite1.5 Dec. 2019 | Elite1.5-re Jan. 2021 | "Elite-EDC" |
|
||||
* | DEF_ELITE_EDC_15R2 | Elite1.5 Dec. 2019 | Elite1.5-r2 May. 2022 | "Elite-EDC" |
|
||||
* | DEF_ELITE_BAT_01 | Elite2.0 Feb. 2022 | "Elite-BAT" |
|
||||
* | DEF_ELITE_BAT_10 | BAT SMC V1.0 Aug.2022| BAT PWR V1.0 Aug. 2022 | "Elite-BAT" |
|
||||
* | DEF_ELITE_EIS_10 | Elite1.5 Dec. 2019 | Elite EIS1.0 Aug. 2020 | "Elite-EIS" |
|
||||
* | DEF_ELITE_EIS_11 | Elite1.5 Dec. 2019 | Elite EIS1.1 Feb. 2022 | "Elite-EIS" |
|
||||
* | DEF_ELITE_EIS_MINI_10 | EIS MINI May. 2022 | "Elite-EIS-MINI" |
|
||||
* | DEF_ELITE_TRIG_01 | Elite TRIG01 Jan. 2021 | "Elite-TRIG" |
|
||||
* | DEF_ELITE_MEGAFLY_01 | Elite1.5 Dec. 2019 | Elite Megafly Sep. 2020 | "Elite-MEGAFLY" |
|
||||
* +------------------------+----------------------+-------------------------+----------------------+
|
||||
*
|
||||
* +------------------------+----------------+----------------------+----------+
|
||||
* | model name | product number | data server lib name | UI |
|
||||
* +------------------------+----------------+----------------------+----------+
|
||||
* | DEF_ELITE_EDC_14 | 0, 2, 1, 5 | Elite_EDC_1.4 | null | -> No longer maintained
|
||||
* | DEF_ELITE_EDC_15 | 0, 2, 1, 6 | Elite_EDC_1.5 | EliteEDC | -> No longer maintained
|
||||
* | DEF_ELITE_EDC_15RE | 0, 2, 1, 7 | Elite_EDC_1.5re | EliteEDC |
|
||||
* | DEF_ELITE_EDC_15R2 | 0, 2, 1, 8 | Elite_EDC_1.5r2 | EliteEDC |
|
||||
* | DEF_ELITE_BAT_01 | 0, 3, 1, 0 | Elite_BAT_1.0 | EliteEDC | -> No longer maintained
|
||||
* | DEF_ELITE_BAT_10 | 0, 3, 1, 1 | Elite_BAT_1.0 | EliteEDC |
|
||||
* | DEF_ELITE_EIS_10 | 0, 4, 1, 0 | Elite_EIS_1.0 | EliteEIS |
|
||||
* | DEF_ELITE_EIS_11 | 0, 4, 1, 1 | Elite_EIS_1.1 | EliteEIS |
|
||||
* | DEF_ELITE_EIS_MINI_10 | 0, 4, 1, 2 | Elite_EIS_MINI_1.0 | EliteEIS |
|
||||
* | DEF_ELITE_TRIG_01 | 0, 5, 1, 0 | Elite_TRIG_0.1 | null |
|
||||
* | DEF_ELITE_MEGAFLY_01 | 0, 6, 1, 0 | Elite_MEGAFLY_0.1 | null | -> No longer maintained
|
||||
* +------------------------+----------------+----------------------+----------+
|
||||
* ps.
|
||||
* model name is FW engineer defined
|
||||
* device name is used for controller
|
||||
*/
|
||||
|
||||
|
||||
#define DEF_ELITE_EDC_14 0
|
||||
#define DEF_ELITE_EDC_15 1
|
||||
#define DEF_ELITE_EDC_15RE 2
|
||||
#define DEF_ELITE_EDC_15R2 3
|
||||
#define DEF_ELITE_BAT_01 4
|
||||
#define DEF_ELITE_BAT_10 5
|
||||
#define DEF_ELITE_EIS_10 6
|
||||
#define DEF_ELITE_EIS_11 7
|
||||
#define DEF_ELITE_EIS_MINI_10 8
|
||||
#define DEF_ELITE_TRIG_01 9
|
||||
#define DEF_ELITE_MEGAFLY_01 10
|
||||
#define DEF_ELITE_MAX 11
|
||||
|
||||
// !!! define DEF_ELITE_MODEL first please !!!
|
||||
#define DEF_ELITE_MODEL DEF_ELITE_BAT_10
|
||||
|
||||
// model information
|
||||
#if (DEF_ELITE_MODEL == DEF_ELITE_EDC_14)
|
||||
#error "code no support"
|
||||
#elif (DEF_ELITE_MODEL == DEF_ELITE_EDC_15)
|
||||
#error "code no support"
|
||||
#elif (DEF_ELITE_MODEL == DEF_ELITE_EDC_15RE)
|
||||
#error "code no support"
|
||||
#elif (DEF_ELITE_MODEL == DEF_ELITE_EDC_15R2)
|
||||
#error "code no support"
|
||||
#elif (DEF_ELITE_MODEL == DEF_ELITE_BAT_01)
|
||||
#error "code no support"
|
||||
#elif (DEF_ELITE_MODEL == DEF_ELITE_BAT_10)
|
||||
#include "app_config_BAT_10.h"
|
||||
#elif (DEF_ELITE_MODEL == DEF_ELITE_EIS_10)
|
||||
#error "code no support"
|
||||
#elif (DEF_ELITE_MODEL == DEF_ELITE_EIS_11)
|
||||
#error "code no support"
|
||||
#elif (DEF_ELITE_MODEL == DEF_ELITE_EIS_MINI_10)
|
||||
#error "code no support"
|
||||
#elif (DEF_ELITE_MODEL == DEF_ELITE_TRIG_01)
|
||||
#error "code no support"
|
||||
#elif (DEF_ELITE_MODEL == DEF_ELITE_MEGAFLY_01)
|
||||
#error "code no support"
|
||||
#else
|
||||
#error "no this model"
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
@@ -0,0 +1,202 @@
|
||||
#pragma once
|
||||
#ifndef BAT_10_CONF_H
|
||||
#define BAT_10_CONF_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define CC2650_CODE 1
|
||||
|
||||
#if(!CC2650_CODE)
|
||||
//cc2650 self-defined"
|
||||
#define DIO5 5
|
||||
#define DIO6 9
|
||||
#define DIO12 12
|
||||
#define DIO13 13
|
||||
#define DIO14 14
|
||||
#define DIO8 8
|
||||
#define DIO9 9
|
||||
#define PIN_UNASSIGNED 0xFF
|
||||
#else
|
||||
/*------device infomation---------------------------------------------------*/
|
||||
#define DEVICE_NAME "Elite-BAT"
|
||||
#define MAJOR_PRODUCT_NUMBER 0
|
||||
#define MINOR_PRODUCT_NUMBER 3
|
||||
#define MAJOR_VERSION_NUMBER 1
|
||||
#define MINOR_VERSION_NUMBER 1
|
||||
#define HARDWARE_VER {MAJOR_PRODUCT_NUMBER, MINOR_PRODUCT_NUMBER, \
|
||||
MAJOR_VERSION_NUMBER, MINOR_VERSION_NUMBER}
|
||||
#endif
|
||||
|
||||
|
||||
//Assign the Elite pins, please
|
||||
//These settings will be referenced by 'BOOSTXL_CC2650MA.h'
|
||||
#define E_PIN_LED_SPI_CLK DIO5
|
||||
#define E_PIN_LED_SPI_SDI DIO6
|
||||
#define E_PIN_SCLK0 DIO12
|
||||
#define E_PIN_MOSI DIO13
|
||||
#define E_PIN_MISO DIO14
|
||||
#define E_PIN_I2C_SCK DIO8
|
||||
#define E_PIN_I2C_SDA DIO9
|
||||
|
||||
//The SPI/I2C pins assigned to CC2650 are referred to as Elite pins
|
||||
#define E_SPI0_MISO PIN_UNASSIGNED
|
||||
#define E_SPI0_MOSI E_PIN_LED_SPI_SDI
|
||||
#define E_SPI0_CLK E_PIN_LED_SPI_CLK
|
||||
#define E_SPI0_CS PIN_UNASSIGNED
|
||||
#define E_SPI1_MISO E_PIN_MISO
|
||||
#define E_SPI1_MOSI E_PIN_MOSI
|
||||
#define E_SPI1_CLK E_PIN_SCLK0
|
||||
#define E_SPI1_CS PIN_UNASSIGNED
|
||||
#define E_I2C0_SCL0 E_PIN_I2C_SCK
|
||||
#define E_I2C0_SDA0 E_PIN_I2C_SDA
|
||||
|
||||
/* cc2650_connection_interface.c */
|
||||
#define I2C_BITRATE_100K 0
|
||||
#define I2C_BITRATE_400K 1
|
||||
|
||||
/* ADG1408x1.c */
|
||||
//select_adc_channel() func parameter: channel
|
||||
#define ADC_CH_VHP0 0
|
||||
#define ADC_CH_VHN0 1
|
||||
#define ADC_CH_IsenHP 2
|
||||
#define ADC_CH_IsenHN 3
|
||||
#define ADC_CH_VHP12 4
|
||||
#define ADC_CH_Vdiff 5
|
||||
#define ADC_CH_VHP1 6
|
||||
#define ADC_CH_VHN1 7
|
||||
|
||||
/* MCP23008x2.c */
|
||||
//set_pin_Vlogic_EN_iodir() func parameter: in_out_flag
|
||||
#define SET_OUTPUT 0
|
||||
#define SET_INPUT 1
|
||||
|
||||
/* ADGS1412x9.c */
|
||||
//ADGS1412_get_one_mux() func para: component_id
|
||||
//ADGS1412_set_one_mux() func para: component_id
|
||||
#define ADGS1412_U14 0
|
||||
#define ADGS1412_U13 1
|
||||
#define ADGS1412_U18 2
|
||||
#define ADGS1412_U20 3
|
||||
#define ADGS1412_U26 4
|
||||
#define ADGS1412_U29 5
|
||||
#define ADGS1412_U22 6
|
||||
#define ADGS1412_U04 7
|
||||
#define ADGS1412_U24 8
|
||||
//ADGS1412_set_one_mux() func para: set_value
|
||||
#define ADGS1412_ALL_DIS 0b00000000
|
||||
#define ADGS1412_S1_EN 0b00000001
|
||||
#define ADGS1412_S2_EN 0b00000010
|
||||
#define ADGS1412_S3_EN 0b00000100
|
||||
#define ADGS1412_S4_EN 0b00001000
|
||||
|
||||
/* MAX5136x2.c */
|
||||
//OUT_n_output() func parameter: out_pin
|
||||
#define DAC_OUT_0 0
|
||||
#define DAC_OUT_1 1
|
||||
#define DAC_OUT_2 2
|
||||
#define DAC_OUT_3 3
|
||||
|
||||
/* ADS8691x1.c */
|
||||
//set_adc_input_range() fun parameter: range
|
||||
#define ADC_MEASURE_RANGE_02V_PN 0 //ADC measure range: +-2.56V LSB:19.53uV
|
||||
#define ADC_MEASURE_RANGE_05V_PN 1 //ADC measure range: +-5.12V LSB:39.06uV
|
||||
#define ADC_MEASURE_RANGE_06V_PN 2 //ADC measure range: +-6.144V LSB:46.875uV
|
||||
#define ADC_MEASURE_RANGE_10V_PN 3 //ADC measure range: +-10.24V LSB:78.125uV
|
||||
#define ADC_MEASURE_RANGE_12V_PN 4 //ADC measure range: +-12.288V LSB:93.75uV
|
||||
|
||||
/* pinout_ser.c */
|
||||
//pinout4_output_source() func para: pin
|
||||
//pinout1_output_source() func para: pin
|
||||
#define VOUT_VctlPIN3 0
|
||||
#define VOUT_VctlPIN2 1
|
||||
#define VOUT_VctlHN 2
|
||||
#define VOUT_VctlHP0 3
|
||||
#define VOUT_VHN_output 4
|
||||
|
||||
/* common fomular */
|
||||
#define HIGH_BYTES_16b(_v) (_v >> 8)
|
||||
#define LOW_BYTES_16b(_v) (_v)
|
||||
|
||||
#if(CC2650_CODE)
|
||||
/* cc2650_connection_interface.c */
|
||||
bool i2c0_write(uint8_t bitRate, uint8_t i2c_addr, uint8_t *i2c_array, uint8_t i2c_array_len);
|
||||
void set_pin_ADCA0(bool boolflag);
|
||||
void set_pin_ADCA1(bool boolflag);
|
||||
void set_pin_ADCA2(bool boolflag);
|
||||
void set_pin_ADCCS(bool boolflag);
|
||||
void set_pin_DACCS(bool boolflag);
|
||||
void set_pin_SWCSBB(bool boolflag);
|
||||
void set_pin_MEMCS(bool boolflag);
|
||||
void set_all_pin_to_default(void);
|
||||
|
||||
/* ADG1408x1.c */
|
||||
void select_adc_channel(uint8_t channel);
|
||||
|
||||
/* MCP23008x2.c */
|
||||
void MCP23008_to_default(void);
|
||||
void set_pin_SWRST(bool boolflag);
|
||||
void set_pin_OSWHP(bool boolflag);
|
||||
void set_pin_OSWHN(bool boolflag);
|
||||
void set_pin_OSWPIN3(bool boolflag);
|
||||
void set_pin_WP(bool boolflag);
|
||||
void set_pin_APHP_EN(bool boolflag);
|
||||
void set_pin_APHP_EN_neg(bool boolflag);
|
||||
void set_pin_INT9466(bool boolflag);
|
||||
void set_pin_Vlogic_EN(bool boolflag); // 'Vlogic_EN' or 'Power_EN'
|
||||
void set_pin_SW_EN(bool boolflag);
|
||||
void set_pin_SW_SEN(bool boolflag);
|
||||
void set_pin_Shutdown(bool boolflag); // 'Shutdown' or 'shut_down'
|
||||
bool get_pin_SW_SEN(void);
|
||||
bool get_pin_INT9466(void);
|
||||
void set_pin_Vlogic_EN_iodir(uint8_t in_out_flag); // 'Vlogic_EN' or 'Power_EN'
|
||||
|
||||
/* ADGS1412x9.c */
|
||||
void ADGS1412_daisy_chain_mode(void);
|
||||
void ADGS1412_idle_conf(void);
|
||||
uint8_t ADGS1412_get_one_mux(uint8_t component_id);
|
||||
void ADGS1412_set_one_mux(uint8_t component_id, uint8_t set_value);
|
||||
|
||||
/* MAX5136x2.c */
|
||||
void OUT_n_output(uint8_t out_pin, uint16_t dac_code);
|
||||
|
||||
/* ADS8691x1.c */
|
||||
void ADS8691_init(void);
|
||||
int32_t get_adc_voltage_uV(void);
|
||||
uint8_t get_adc_input_range(void);
|
||||
int8_t set_adc_input_range(uint8_t range);
|
||||
|
||||
/* MCP45HV51x2.c*/
|
||||
void set_SW_P_voltage(int32_t uv);
|
||||
void set_SW_N_voltage(int32_t uv);
|
||||
|
||||
/* pinout_ser.c */
|
||||
int8_t pinout1_output_source(uint8_t pin);
|
||||
int8_t pinout4_output_source(uint8_t pin);
|
||||
void pinout1_volt_output(int32_t uv);
|
||||
void pinout2_volt_output(int32_t uv);
|
||||
void pinout3_volt_output(int32_t uv);
|
||||
void pinout4_volt_output(int32_t uv);
|
||||
void pinout1_output(bool boolflag);
|
||||
void pinout2_3_input_mode(void);
|
||||
void pinout2_output_mode(void);
|
||||
void pinout3_output_mode(void);
|
||||
void pinout3_connect_GND(bool boolflag);
|
||||
int32_t read_Vdiff(void);
|
||||
int32_t read_IsenHP(void);
|
||||
int32_t read_IsenHN(void);
|
||||
int32_t read_VHP0(void);
|
||||
int32_t read_VHP1(void);
|
||||
int32_t read_VHN0(void);
|
||||
int32_t read_VHN1(void);
|
||||
int32_t read_VHP12(void);
|
||||
void pinout_ser_to_default(void);
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // !__ELITE_APP_CONFIG_H__
|
||||
@@ -1,6 +0,0 @@
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,797 @@
|
||||
#include <stdint.h>
|
||||
|
||||
#include "application/pinout_ser.h"
|
||||
|
||||
/*
|
||||
* MODE_DEV_TOOL 0xFF
|
||||
* DEV_TOOL_VERSION [34 LL FF 01]
|
||||
*
|
||||
* DEV_TOOL_BAT [34 LL FF 02]
|
||||
*
|
||||
* DEV_TOOL_TEMP [34 LL FF 03]
|
||||
*
|
||||
* DEV_TOOL_LED [34 LL FF 04]
|
||||
* DEV_LED_LIMIT_COLOR [00 NN]
|
||||
* DEV_LED_DARK_COLOR [01 RR GG BB]
|
||||
* DEV_LED_LIGHT_COLOR [02 RR GG BB]
|
||||
* DEV_LED_RAINBOW [03]
|
||||
*
|
||||
* DEV_TOOL_SPI [34 LL FF 20 pp RR WW ss ss ss ...]
|
||||
* DT_CHIP_ADC pp = [00]
|
||||
* DT_CHIP_DAC pp = [01]
|
||||
* DT_CHIP_MEM pp = [02]
|
||||
* DT_CHIP_SWITCH pp = [03]
|
||||
*
|
||||
* DEV_TOOL_I2C [34 LL FF 28 qq RR WW ss ss ss ...]
|
||||
*
|
||||
* DEV_TOOL_GPIO_EDC20_ADC_CH [34 LL FF 31 cc]
|
||||
* cc = 07 => all open
|
||||
* cc = 04 => open A2
|
||||
* cc = 02 => open A1
|
||||
* cc = 01 => open A0
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
enum dev_tool_para_e {
|
||||
DEV_TOOL_VERSION = 0x01,
|
||||
DEV_TOOL_BAT = 0x02,
|
||||
DEV_TOOL_TEMP = 0x03,
|
||||
DEV_TOOL_LED = 0x04,
|
||||
DEV_TOOL_SPI = 0x20,
|
||||
DEV_TOOL_I2C = 0x28,
|
||||
DEV_TOOL_GPIO_EDC20_ADC_CH = 0x31,
|
||||
DEV_TOOL_OUT0_WRITE_THROUGH = 0x50,
|
||||
DEV_TOOL_SWITCH_SELECT = 0x60,
|
||||
};
|
||||
|
||||
enum dev_tool_chip_e {
|
||||
DT_CHIP_ADC = 0,
|
||||
DT_CHIP_DAC,
|
||||
DT_CHIP_MEM,
|
||||
DT_CHIP_SWITCH,
|
||||
DT_OPEN_SPI1 = 0x11,
|
||||
|
||||
DT_CHIP_MAX,
|
||||
};
|
||||
|
||||
enum dev_led_item_e {
|
||||
DEV_LED_LIMIT_COLOR = 0,
|
||||
DEV_LED_DARK_COLOR,
|
||||
DEV_LED_LIGHT_COLOR,
|
||||
DEV_LED_RAINBOW,
|
||||
DEV_LED_LV0_COLOR,
|
||||
|
||||
DEV_LED_MAX,
|
||||
};
|
||||
|
||||
// RIS (real instruction)
|
||||
enum all_mode_e {
|
||||
MODE_DEV_TOOL = 0xFF, // Dev Mode
|
||||
};
|
||||
|
||||
// CIS (control instruction)
|
||||
#define CIS_VERSION 0x40
|
||||
#define CIS_VOLT 0x10
|
||||
#define CIS_TEMPERATURE 0x80
|
||||
|
||||
static void dev_tool_version()
|
||||
{
|
||||
uint8_t cis_buf[BLE_CIS_BUFF_SIZE] = {0};
|
||||
cis_buf[0] = 6; //data len
|
||||
cis_buf[1] = DEV_TOOL_VERSION;
|
||||
cis_buf[2] = VERSION_DATE_YEAR;
|
||||
cis_buf[3] = VERSION_DATE_MONTH;
|
||||
cis_buf[4] = VERSION_DATE_DAY;
|
||||
cis_buf[5] = VERSION_DATE_HOUR;
|
||||
cis_buf[6] = VERSION_DATE_MINUTE;
|
||||
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, BLE_CIS_BUFF_SIZE, cis_buf);
|
||||
}
|
||||
|
||||
static void dev_tool_battery()
|
||||
{
|
||||
uint8_t cis_buf[BLE_CIS_BUFF_SIZE] = {0};
|
||||
cis_buf[0] = 5; //data len
|
||||
cis_buf[1] = DEV_TOOL_BAT;
|
||||
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, BLE_CIS_BUFF_SIZE, cis_buf);
|
||||
}
|
||||
|
||||
static void dev_tool_temp()
|
||||
{
|
||||
uint8_t cis_buf[BLE_CIS_BUFF_SIZE] = {0};
|
||||
cis_buf[0] = 5; //data len
|
||||
cis_buf[1] = DEV_TOOL_TEMP;
|
||||
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, BLE_CIS_BUFF_SIZE, cis_buf);
|
||||
}
|
||||
|
||||
static int dev_tool_led(uint8_t *ins_buf)
|
||||
{
|
||||
uint8_t *p = ins_buf;
|
||||
struct led_color_t led_c;
|
||||
uint8_t led_item = p[4];
|
||||
uint8_t c_num = p[5];
|
||||
|
||||
led_c.r = p[5];
|
||||
led_c.g = p[6];
|
||||
led_c.b = p[7];
|
||||
|
||||
if (led_item >= DEV_LED_MAX)
|
||||
return -1;
|
||||
|
||||
if (led_item == DEV_LED_RAINBOW) //03
|
||||
return led_rainbow(LED_BR_LV1);
|
||||
|
||||
if (led_item == DEV_LED_LIMIT_COLOR) //00
|
||||
return led_color_set(LED_NB_MAX, LED_BR_LV1, (enum led_color_e)c_num);
|
||||
|
||||
if (led_item == DEV_LED_DARK_COLOR) //01
|
||||
return led_color_code_set(LED_NB_MAX, LED_BR_LV1, &led_c); //0401RRGGBB
|
||||
|
||||
if (led_item == DEV_LED_LIGHT_COLOR) //02
|
||||
return led_color_code_set(LED_NB_MAX, LED_BR_LV8, &led_c); //0402RRGGBB
|
||||
|
||||
if (led_item == DEV_LED_LV0_COLOR) //04
|
||||
return led_color_code_set(LED_NB_MAX, LED_BR_LV0, &led_c); //0404RRGGBB
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void dev_tool_spi(uint8_t *ins_buf)
|
||||
{
|
||||
uint8_t *p = ins_buf;
|
||||
uint8_t chip_sel = p[4];
|
||||
|
||||
//ADC、DAC、MEM、SWITCH
|
||||
uint8_t rxlen = p[5];
|
||||
uint8_t txlen = p[6];
|
||||
uint8_t rx[32] = {0};
|
||||
|
||||
//set spi config
|
||||
static uint8_t pol = 0;
|
||||
static uint8_t pha = 0;
|
||||
|
||||
if (chip_sel >= DT_CHIP_MAX)
|
||||
return;
|
||||
|
||||
switch (chip_sel) {
|
||||
case DT_CHIP_ADC:
|
||||
spi1_open(SPI_CLK_4M, pol, pha);
|
||||
set_pin_ADCCS(0);
|
||||
spi1_write(rx, &p[7], txlen);
|
||||
set_pin_ADCCS(1);
|
||||
spi1_close();
|
||||
break;
|
||||
|
||||
case DT_CHIP_DAC:
|
||||
spi1_open(SPI_CLK_4M, pol, pha);
|
||||
set_pin_DACCS(0);
|
||||
spi1_write(rx, &p[7], txlen);
|
||||
set_pin_DACCS(1);
|
||||
spi1_close();
|
||||
break;
|
||||
|
||||
case DT_CHIP_MEM:
|
||||
spi1_open(SPI_CLK_4M, pol, pha);
|
||||
set_pin_MEMCS(0);
|
||||
spi1_write(rx, &p[7], txlen);
|
||||
set_pin_MEMCS(1);
|
||||
spi1_close();
|
||||
break;
|
||||
|
||||
case DT_CHIP_SWITCH:
|
||||
spi1_open(SPI_CLK_4M, pol, pha);
|
||||
set_pin_SWCSBB(0);
|
||||
spi1_write(rx, &p[7], txlen);
|
||||
set_pin_SWCSBB(1);
|
||||
spi1_close();
|
||||
break;
|
||||
|
||||
case DT_OPEN_SPI1:
|
||||
pol = p[5] >> 4;
|
||||
pha = p[5] & 0X0F;
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
uint8_t cis_buf[BLE_CIS_BUFF_SIZE] = {0}; cis_buf[0] = rxlen + 1; //data len
|
||||
cis_buf[1] = DEV_TOOL_SPI;
|
||||
memcpy(&cis_buf[2], rx, rxlen);
|
||||
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, BLE_CIS_BUFF_SIZE, cis_buf);
|
||||
|
||||
}
|
||||
|
||||
static void dev_tool_i2c(uint8_t *ins_buf)
|
||||
{
|
||||
uint8_t *p = ins_buf;
|
||||
uint8_t i2c_addr = p[4] >> 1;
|
||||
uint8_t ret_i2c_len = p[5];
|
||||
uint8_t i2c_array_len = p[6];
|
||||
uint8_t i2c_array[20];
|
||||
|
||||
memcpy(i2c_array, &p[7], i2c_array_len);
|
||||
|
||||
i2c0_write(I2C_BITRATE_400K, i2c_addr, i2c_array, i2c_array_len);
|
||||
|
||||
uint8_t cis_buf[BLE_CIS_BUFF_SIZE] = {0};
|
||||
cis_buf[0] = ret_i2c_len + 2; //data len
|
||||
cis_buf[1] = DEV_TOOL_I2C;
|
||||
memcpy(&cis_buf[2], i2c_array, ret_i2c_len);
|
||||
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, BLE_CIS_BUFF_SIZE, cis_buf);
|
||||
}
|
||||
|
||||
static void dev_tool_gpio_edc20_adc_ch(uint8_t *ins_buf)
|
||||
{
|
||||
uint8_t *p = ins_buf;
|
||||
uint8_t adc_selector = p[4];
|
||||
|
||||
select_adc_channel(adc_selector);
|
||||
|
||||
uint8_t cis_buf[BLE_CIS_BUFF_SIZE] = {0};
|
||||
cis_buf[0] = 2; //data len
|
||||
cis_buf[1] = DEV_TOOL_GPIO_EDC20_ADC_CH;
|
||||
cis_buf[2] = adc_selector;
|
||||
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, BLE_CIS_BUFF_SIZE, cis_buf);
|
||||
}
|
||||
|
||||
static void set_pinout2_and_pinout3_as_input(void)
|
||||
{
|
||||
Vdiff_gain(0);
|
||||
Vdiff_input_resis_route(LOAD_RESIS);
|
||||
pinout2_3_input_mode();
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* reset power control
|
||||
*/
|
||||
static void ADS8691_reset_power_control(void)
|
||||
{
|
||||
uint8_t RST_PWRCTL_REG[4] = {0xD0, 0x04, 0x69, 0x04};
|
||||
spi1_open(SPI_CLK_4M, POL1, PHA0);
|
||||
set_pin_ADCCS(0);
|
||||
spi1_write(NULL, RST_PWRCTL_REG, sizeof(RST_PWRCTL_REG));
|
||||
set_pin_ADCCS(1);
|
||||
spi1_close();
|
||||
}
|
||||
|
||||
/*
|
||||
* 0x90 for test mode
|
||||
*/
|
||||
static void dev_tool_change_instruction_para_value(uint8_t *ins_buf)
|
||||
{
|
||||
uint8_t para = ins_buf[4];
|
||||
|
||||
switch (para) {
|
||||
case 0x01:
|
||||
instru.volt_1 = (int32_t)ins_buf[5] << 24 | (int32_t)ins_buf[6] << 16 | (int32_t)ins_buf[7] << 8 | (int32_t)ins_buf[8];
|
||||
break;
|
||||
|
||||
case 0x02:
|
||||
instru.volt_4 = (int32_t)ins_buf[5] << 24 | (int32_t)ins_buf[6] << 16 | (int32_t)ins_buf[7] << 8 | (int32_t)ins_buf[8];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*******************************************************/
|
||||
|
||||
/*
|
||||
* 0xA0 ~ 0xA7 for developer
|
||||
*/
|
||||
static void dev_tool_control_mcp23008(uint8_t *ins_buf)
|
||||
{
|
||||
uint8_t pin = ins_buf[4];
|
||||
bool signal = ins_buf[5];
|
||||
bool ret;
|
||||
uint8_t ack_buf[20] = {0};
|
||||
|
||||
switch (pin) {
|
||||
case 0x01:
|
||||
set_pin_SWRST(signal);
|
||||
break;
|
||||
|
||||
case 0x02:
|
||||
set_pin_OSWHP(signal);
|
||||
break;
|
||||
|
||||
case 0x03:
|
||||
set_pin_OSWHN(signal);
|
||||
break;
|
||||
|
||||
case 0x04:
|
||||
set_pin_OSWPIN3(signal);
|
||||
break;
|
||||
|
||||
case 0x05:
|
||||
set_pin_WP(signal);
|
||||
break;
|
||||
|
||||
case 0x06:
|
||||
set_pin_APHP_EN(signal);
|
||||
break;
|
||||
|
||||
case 0x07:
|
||||
set_pin_APHP_EN_neg(signal);
|
||||
break;
|
||||
|
||||
case 0x08: {
|
||||
ret = get_pin_INT9466(); //input
|
||||
ack_buf[0] = 2; //data len
|
||||
ack_buf[1] = 0xA0;
|
||||
ack_buf[2] = ret;
|
||||
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, BLE_CIS_BUFF_SIZE, ack_buf);
|
||||
break;
|
||||
}
|
||||
|
||||
case 0x09:
|
||||
set_pin_Vlogic_EN(signal);
|
||||
break;
|
||||
|
||||
case 0x0A:
|
||||
set_pin_SW_EN(signal);
|
||||
break;
|
||||
|
||||
case 0x0B: {
|
||||
ret = get_pin_SW_SEN(); //input
|
||||
ack_buf[0] = 2; //data len
|
||||
ack_buf[1] = 0xA0;
|
||||
ack_buf[2] = ret;
|
||||
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, BLE_CIS_BUFF_SIZE, ack_buf);
|
||||
break;
|
||||
}
|
||||
|
||||
case 0x0C:
|
||||
set_pin_Shutdown(signal);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void dev_tool_select_adc_channel(uint8_t *ins_buf)
|
||||
{
|
||||
uint8_t channel = ins_buf[4];
|
||||
|
||||
switch (channel) {
|
||||
case 0x01:
|
||||
select_adc_channel(ADC_CH_VHP0);
|
||||
break;
|
||||
|
||||
case 0x02:
|
||||
select_adc_channel(ADC_CH_VHN0);
|
||||
break;
|
||||
|
||||
case 0x03:
|
||||
select_adc_channel(ADC_CH_IsenHP);
|
||||
break;
|
||||
|
||||
case 0x04:
|
||||
select_adc_channel(ADC_CH_IsenHN);
|
||||
break;
|
||||
|
||||
case 0x05:
|
||||
select_adc_channel(ADC_CH_VHP12);
|
||||
break;
|
||||
|
||||
case 0x06:
|
||||
select_adc_channel(ADC_CH_Vdiff);
|
||||
break;
|
||||
|
||||
case 0x07:
|
||||
select_adc_channel(ADC_CH_VHP1);
|
||||
break;
|
||||
|
||||
case 0x08:
|
||||
select_adc_channel(ADC_CH_VHN1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void dev_tool_set_adc_input_range(uint8_t *ins_buf)
|
||||
{
|
||||
uint8_t ret;
|
||||
uint8_t ack_buf[20] = {0};
|
||||
|
||||
switch (ins_buf[4]) {
|
||||
case 0xFF:
|
||||
ret = get_adc_input_range();
|
||||
ack_buf[0] = 2; //data len
|
||||
ack_buf[1] = 0xA2;
|
||||
ack_buf[2] = ret;
|
||||
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, BLE_CIS_BUFF_SIZE, ack_buf);
|
||||
break;
|
||||
|
||||
case 0x01:
|
||||
set_adc_input_range(ADC_MEASURE_RANGE_02V_PN);
|
||||
break;
|
||||
|
||||
case 0x02:
|
||||
set_adc_input_range(ADC_MEASURE_RANGE_05V_PN);
|
||||
break;
|
||||
|
||||
case 0x03:
|
||||
set_adc_input_range(ADC_MEASURE_RANGE_06V_PN);
|
||||
break;
|
||||
|
||||
case 0x04:
|
||||
set_adc_input_range(ADC_MEASURE_RANGE_10V_PN);
|
||||
break;
|
||||
|
||||
case 0x05:
|
||||
set_adc_input_range(ADC_MEASURE_RANGE_12V_PN);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void dev_tool_set_IsenHN_IsenHP_Vdiff_gain(uint8_t *ins_buf)
|
||||
{
|
||||
uint8_t channel = ins_buf[4];
|
||||
uint8_t gain_level = ins_buf[5];
|
||||
|
||||
switch (channel) {
|
||||
case 0x01:
|
||||
IsenHP_gain(gain_level);
|
||||
break;
|
||||
|
||||
case 0x02:
|
||||
IsenHN_gain(gain_level);
|
||||
break;
|
||||
|
||||
case 0x03:
|
||||
Vdiff_gain(gain_level);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void dev_tool_read_adc_volt(uint8_t *ins_buf)
|
||||
{
|
||||
uint8_t channel = ins_buf[4];
|
||||
int32_t uv = 0;
|
||||
uint8_t ack_buf[20] = {0};
|
||||
|
||||
switch (channel) {
|
||||
case 0x01:
|
||||
uv = read_Vdiff();
|
||||
break;
|
||||
|
||||
case 0x02:
|
||||
uv = read_IsenHP();
|
||||
break;
|
||||
|
||||
case 0x03:
|
||||
uv = read_IsenHN();
|
||||
break;
|
||||
|
||||
case 0x04:
|
||||
uv = read_VHP0();
|
||||
break;
|
||||
|
||||
case 0x05:
|
||||
uv = read_VHP1();
|
||||
break;
|
||||
|
||||
case 0x06:
|
||||
uv = read_VHN0();
|
||||
break;
|
||||
|
||||
case 0x07:
|
||||
uv = read_VHN1();
|
||||
break;
|
||||
|
||||
case 0x08:
|
||||
uv = read_VHP12();
|
||||
break;
|
||||
}
|
||||
|
||||
ack_buf[0] = 5; //data len
|
||||
ack_buf[1] = 0xA4;
|
||||
ack_buf[2] = uv>>24;
|
||||
ack_buf[3] = uv>>16;
|
||||
ack_buf[4] = uv>>8;
|
||||
ack_buf[5] = uv;
|
||||
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, BLE_CIS_BUFF_SIZE, ack_buf);
|
||||
}
|
||||
|
||||
static void dev_tool_set_pinout_volt(uint8_t *ins_buf)
|
||||
{
|
||||
uint8_t pinout = ins_buf[4];
|
||||
int32_t uv = (int32_t)ins_buf[5]<<24 | (int32_t)ins_buf[6]<<16 | (int32_t)ins_buf[7]<<8 | (int32_t)ins_buf[8];
|
||||
|
||||
switch (pinout) {
|
||||
case 0x01:
|
||||
pinout1_volt_output(uv);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void dev_tool_set_one_mux(uint8_t *ins_buf)
|
||||
{
|
||||
uint8_t component = ins_buf[4];
|
||||
uint8_t mux_value = ins_buf[5];
|
||||
|
||||
ADGS1412_set_one_mux(component, mux_value);
|
||||
}
|
||||
|
||||
static void dev_tool_read_one_mux(uint8_t *ins_buf)
|
||||
{
|
||||
uint8_t component = ins_buf[4];
|
||||
uint8_t mux_value;
|
||||
uint8_t ack_buf[20] = {0};
|
||||
|
||||
mux_value = ADGS1412_get_one_mux(component);
|
||||
ack_buf[0] = 2; //data len
|
||||
ack_buf[1] = 0xA7;
|
||||
ack_buf[2] = mux_value;
|
||||
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, BLE_CIS_BUFF_SIZE, ack_buf);
|
||||
}
|
||||
|
||||
/*******************************************************/
|
||||
#define ADC_CH_VHP0 0
|
||||
#define ADC_CH_VHN0 1
|
||||
#define ADC_CH_IsenHP 2
|
||||
#define ADC_CH_IsenHN 3
|
||||
#define ADC_CH_VHP12 4
|
||||
#define ADC_CH_Vdiff 5
|
||||
#define ADC_CH_VHP1 6
|
||||
#define ADC_CH_VHN1 7
|
||||
|
||||
static uint32_t get_18bit_adc_value(void);
|
||||
static void mode_dev_tool(uint8_t *ins_buf)
|
||||
{
|
||||
uint8_t *p = ins_buf;
|
||||
uint8_t dev_item = p[3];
|
||||
|
||||
switch (dev_item) {
|
||||
case DEV_TOOL_VERSION:
|
||||
dev_tool_version();
|
||||
break;
|
||||
|
||||
case DEV_TOOL_BAT:
|
||||
dev_tool_battery();
|
||||
break;
|
||||
|
||||
case DEV_TOOL_TEMP:
|
||||
dev_tool_temp();
|
||||
break;
|
||||
|
||||
case DEV_TOOL_LED:
|
||||
dev_tool_led(p);
|
||||
break;
|
||||
|
||||
case DEV_TOOL_SPI:
|
||||
dev_tool_spi(p);
|
||||
break;
|
||||
|
||||
case DEV_TOOL_I2C: //0x28
|
||||
dev_tool_i2c(p);
|
||||
break;
|
||||
|
||||
case DEV_TOOL_GPIO_EDC20_ADC_CH:
|
||||
dev_tool_gpio_edc20_adc_ch(p);
|
||||
break;
|
||||
|
||||
/*
|
||||
* 0x90 for test mode
|
||||
*/
|
||||
case 0x90:
|
||||
dev_tool_change_instruction_para_value(p);
|
||||
break;
|
||||
/*******************************************************/
|
||||
|
||||
/*
|
||||
* 0xA0 ~ 0xA7 for developer
|
||||
*/
|
||||
case 0xA0:
|
||||
dev_tool_control_mcp23008(p);
|
||||
break;
|
||||
|
||||
case 0xA1:
|
||||
dev_tool_select_adc_channel(p);
|
||||
break;
|
||||
|
||||
case 0xA2:
|
||||
dev_tool_set_adc_input_range(p);
|
||||
break;
|
||||
|
||||
case 0xA3:
|
||||
dev_tool_set_IsenHN_IsenHP_Vdiff_gain(p);
|
||||
break;
|
||||
|
||||
case 0xA4:
|
||||
dev_tool_read_adc_volt(p);
|
||||
break;
|
||||
|
||||
case 0xA5:
|
||||
dev_tool_set_pinout_volt(p);
|
||||
break;
|
||||
|
||||
case 0xA6:
|
||||
dev_tool_set_one_mux(p);
|
||||
break;
|
||||
|
||||
case 0xA7:
|
||||
dev_tool_read_one_mux(p);
|
||||
break;
|
||||
/*******************************************************/
|
||||
|
||||
default:
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
#define CURVE_VO 3
|
||||
#define CURVE_SYNC_VOLT 6
|
||||
static void ins_decode_ris(uint8_t *ins_buf)
|
||||
{
|
||||
uint8_t mode = ins_buf[2];
|
||||
|
||||
switch (mode) {
|
||||
case MODE_DEV_TOOL: // 0x3000FF
|
||||
mode_dev_tool(ins_buf);
|
||||
break;
|
||||
|
||||
case CURVE_VO: // 0x300003
|
||||
instru.eliteFxn = CURVE_VO; //0x3000037530000103E8
|
||||
instru.volt_1 = (((int32_t)ins_buf[3] << 8 | (int32_t)ins_buf[4]) - 25000)/5*1000; //1uV
|
||||
instru.volt_4 = 0;
|
||||
instru.notifyRate = 10000 / ((uint32_t)ins_buf[7] << 8 | (uint32_t)ins_buf[8]) * 10;
|
||||
// instru.notifyRate = 10000;
|
||||
turn_led(WORK_LED);
|
||||
break;
|
||||
|
||||
case 0x06: // 0x300006
|
||||
instru.eliteFxn = CURVE_SYNC_VOLT; //0x300006
|
||||
instru.notifyRate = 10000 / ((uint32_t)ins_buf[7] << 8 | (uint32_t)ins_buf[8]) * 10;
|
||||
turn_led(WORK_LED);
|
||||
break;
|
||||
|
||||
case 0xE2: // change para
|
||||
if (ins_buf[3] == 0x01) //DAC_VOLT=0x01
|
||||
instru.volt_1 = (((int32_t)ins_buf[4] << 8 | (int32_t)ins_buf[5]) - 25000)/5*1000; //1uV
|
||||
break;
|
||||
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// VIS (virtual instruction)
|
||||
#define VIS_RST 0xF0
|
||||
#define VIS_STI 0xC0
|
||||
#define VIS_INT 0x60
|
||||
#define VIS_DEVICE_SHINY 0x10
|
||||
#define VIS_SHINY_DIS 0x20
|
||||
|
||||
static void ins_decode_vis(uint8_t *ins_buf)
|
||||
{
|
||||
uint8_t *p = ins_buf;
|
||||
uint8_t oper = p[1]; // this is don't care in RIS
|
||||
switch (oper) {
|
||||
// reset all variables ( Ins = 0xC0F0)
|
||||
case VIS_RST: {
|
||||
instru.eliteFxn = VIS_RST;
|
||||
reset();
|
||||
pinout_ser_to_default();
|
||||
break;
|
||||
}
|
||||
|
||||
case VIS_STI: {
|
||||
uint8_t not_buf[BLE_DAT_BUFF_SIZE] = {0};
|
||||
not_buf[0] = instru.chip_id;
|
||||
|
||||
for(int i = 0; i < 12; i++) {
|
||||
SimpleProfile_SetParameter(BLE_DAT_BUFF_CHAR, sizeof(not_buf), not_buf);
|
||||
}
|
||||
PeriodicEvent = true;
|
||||
mode_init = true;
|
||||
break;
|
||||
}
|
||||
|
||||
case VIS_INT: {
|
||||
reset();
|
||||
pinout_ser_to_default();
|
||||
uint8_t not_buf[BLE_DAT_BUFF_SIZE] = {0};
|
||||
|
||||
not_buf[0] = instru.chip_id;
|
||||
for (int i = 0; i < 12; i++) {
|
||||
SimpleProfile_SetParameter(BLE_DAT_BUFF_CHAR, sizeof(not_buf), not_buf);
|
||||
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case VIS_DEVICE_SHINY: {
|
||||
led_color_set(LED_NB_MAX, LED_BR_LV1, LED_CLR_MAGENTA);
|
||||
break;
|
||||
}
|
||||
|
||||
case VIS_SHINY_DIS: {
|
||||
if (PeriodicEvent) {
|
||||
turn_led(WORK_LED);
|
||||
} else if (!PeriodicEvent) {
|
||||
turn_led(LAST_LED);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void ins_decode_cis(uint8_t *ins_buf)
|
||||
{
|
||||
uint8_t *p = ins_buf;
|
||||
uint8_t oper = p[1]; // this is don't care in RIS
|
||||
|
||||
switch (oper) {
|
||||
case CIS_VERSION: {
|
||||
uint8_t cis_buf[BLE_CIS_BUFF_SIZE] = {0};
|
||||
cis_buf[0] = 6; //data len
|
||||
cis_buf[1] = CIS_VERSION;
|
||||
cis_buf[2] = VERSION_DATE_YEAR;
|
||||
cis_buf[3] = VERSION_DATE_MONTH;
|
||||
cis_buf[4] = VERSION_DATE_DAY;
|
||||
cis_buf[5] = VERSION_DATE_HOUR;
|
||||
cis_buf[6] = VERSION_DATE_MINUTE;
|
||||
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, BLE_CIS_BUFF_SIZE, cis_buf);
|
||||
break;
|
||||
}
|
||||
|
||||
case CIS_VOLT: {
|
||||
uint8_t cis_buf[BLE_CIS_BUFF_SIZE] = {0};
|
||||
cis_buf[0] = 3; //data len
|
||||
cis_buf[1] = CIS_VOLT;
|
||||
cis_buf[2] = 0;
|
||||
cis_buf[3] = 0;
|
||||
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, BLE_CIS_BUFF_SIZE, cis_buf);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
|
||||
case CIS_TEMPERATURE: { //0x7080
|
||||
uint8_t cis_buf[BLE_CIS_BUFF_SIZE] = {0};
|
||||
cis_buf[0] = 5; //data len
|
||||
cis_buf[1] = CIS_TEMPERATURE;
|
||||
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, BLE_CIS_BUFF_SIZE, cis_buf);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// define BT instruction
|
||||
#define INS_TYPE_RIS 0x30
|
||||
#define INS_TYPE_VIS 0xC0
|
||||
#define INS_TYPE_CIS 0x70
|
||||
|
||||
static void decode_elite_instruction(uint8_t *ins_buf)
|
||||
{
|
||||
uint8_t *p = ins_buf;
|
||||
|
||||
uint8_t ins_type = p[0] & 0xF0;
|
||||
uint8_t chip_ID = p[0] & 0x0F;
|
||||
instru.chip_id = chip_ID;
|
||||
|
||||
switch (ins_type) {
|
||||
case INS_TYPE_RIS:
|
||||
ins_decode_ris(p);
|
||||
break;
|
||||
|
||||
case INS_TYPE_VIS:
|
||||
ins_decode_vis(p);
|
||||
break;
|
||||
|
||||
case INS_TYPE_CIS:
|
||||
ins_decode_cis(p);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,92 +0,0 @@
|
||||
#ifndef BAT_10_CONF_H
|
||||
#define BAT_10_CONF_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* --------------------
|
||||
* define device name
|
||||
* ------------------*/
|
||||
#define DEVICE_NAME "Elite-BAT"
|
||||
#define MAJOR_PRODUCT_NUMBER 0
|
||||
#define MINOR_PRODUCT_NUMBER 3
|
||||
#define MAJOR_VERSION_NUMBER 1
|
||||
#define MINOR_VERSION_NUMBER 1
|
||||
|
||||
|
||||
/* ---------------------------
|
||||
* define device buffer size
|
||||
* -------------------------*/
|
||||
#define CUSTOM_GATT_LENGTH
|
||||
#define BLE_CIS_BUFF_SIZE 20
|
||||
#define BLE_INS_BUFF_SIZE 20
|
||||
#define BLE_DAT_BUFF_SIZE 40
|
||||
|
||||
/* -------------------
|
||||
* define device pin
|
||||
* -----------------*/
|
||||
// Elite Pin Board
|
||||
#define E_PIN_LED_SPI_CLK DIO5
|
||||
#define E_PIN_LED_SPI_SDI DIO6
|
||||
#define E_PIN_ADCA0 DIO0
|
||||
#define E_PIN_ADCA1 DIO1
|
||||
#define E_PIN_ADCA2 DIO7
|
||||
#define E_PIN_SWCSBB DIO2
|
||||
#define E_PIN_MEMCS DIO3
|
||||
#define E_PIN_DIO4 DIO4
|
||||
#define E_PIN_I2C_SCK DIO8
|
||||
#define E_PIN_I2C_SDA DIO9
|
||||
#define E_PIN_DACCS DIO10
|
||||
#define E_PIN_ADCCS DIO11
|
||||
#define E_PIN_SCLK0 DIO12
|
||||
#define E_PIN_MOSI DIO13
|
||||
#define E_PIN_MISO DIO14
|
||||
|
||||
// SPI & I2C Board
|
||||
#define E_SPI0_MISO PIN_UNASSIGNED
|
||||
#define E_SPI0_MOSI E_PIN_LED_SPI_SDI
|
||||
#define E_SPI0_CLK E_PIN_LED_SPI_CLK
|
||||
#define E_SPI0_CS PIN_UNASSIGNED
|
||||
|
||||
#define E_SPI1_MISO E_PIN_MISO
|
||||
#define E_SPI1_MOSI E_PIN_MOSI
|
||||
#define E_SPI1_CLK E_PIN_SCLK0
|
||||
#define E_SPI1_CS PIN_UNASSIGNED
|
||||
|
||||
#define E_I2C0_SCL0 E_PIN_I2C_SCK
|
||||
#define E_I2C0_SDA0 E_PIN_I2C_SDA
|
||||
|
||||
// no use
|
||||
#define D0 PIN_UNASSIGNED
|
||||
#define D1 PIN_UNASSIGNED
|
||||
#define D2 PIN_UNASSIGNED
|
||||
#define D3 PIN_UNASSIGNED
|
||||
#define D4 PIN_UNASSIGNED
|
||||
#define D5 PIN_UNASSIGNED
|
||||
#define D6 PIN_UNASSIGNED
|
||||
#define D7 PIN_UNASSIGNED
|
||||
#define LOAD0 PIN_UNASSIGNED
|
||||
#define LOAD1 PIN_UNASSIGNED
|
||||
#define LOAD2 PIN_UNASSIGNED
|
||||
|
||||
#define SHUT_DOWN PIN_UNASSIGNED //switch_on
|
||||
#define HIGH_Z LOAD0, PIN_UNASSIGNED
|
||||
#define CS_MEM LOAD0, PIN_UNASSIGNED
|
||||
#define CS_ADC LOAD0, PIN_UNASSIGNED
|
||||
#define CS_DAC LOAD0, PIN_UNASSIGNED
|
||||
#define MEM_HOLD LOAD1, PIN_UNASSIGNED
|
||||
#define P_10V_enable LOAD1, PIN_UNASSIGNED
|
||||
#define P_5V_enable LOAD1, PIN_UNASSIGNED
|
||||
#define I_MID_ON LOAD2, PIN_UNASSIGNED
|
||||
#define I_LARGE_ON LOAD2, PIN_UNASSIGNED
|
||||
#define V_SMALL_ON LOAD2, PIN_UNASSIGNED
|
||||
#define V_MID_ON LOAD2, PIN_UNASSIGNED
|
||||
#define I_SMALL_ON LOAD2, PIN_UNASSIGNED
|
||||
#define OFF LOAD2, PIN_UNASSIGNED //6994
|
||||
#define VOUT_SMALL_ON LOAD2, PIN_UNASSIGNED
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
@@ -1,159 +0,0 @@
|
||||
|
||||
#ifndef APPLICATION_CONFIG_H
|
||||
#define APPLICATION_CONFIG_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// !!! define DEF_ELITE_MODEL first please !!!
|
||||
|
||||
/*
|
||||
*
|
||||
* product number: MAJOR_PRODUCT_NUMBER, MINOR_PRODUCT_NUMBER, MAJOR_VERSION_NUMBER, MINOR_VERSION_NUMBER
|
||||
* MAJOR_PRODUCT_NUMBER -> 0:Elite, 1:other serial
|
||||
* Elite:
|
||||
* MINOR_PRODUCT_NUMBER -> 1:legacy, 2:EDC, 3:BAT, 4:EIS, 5:TRIG, 6:MEGAFLY
|
||||
*
|
||||
* |------------------+------------------------+----------------------+-------------------------+----------------+----------------------+----------------------+----------+
|
||||
* | hardware | model name | hw upper board | hw lower board | product number | device name | data server lib name | UI |
|
||||
* |------------------+------------------------+----------------------+-------------------------+----------------+----------------------+----------------------+----------+
|
||||
* | Elite EDC1.4 | DEF_ELITE_EDC_14 | Elite1.4-re Jun.2019 | Elite1.4-re Jun. 2019 | 0, 2, 1, 5 | "Elite-EDC" | Elite_EDC_1.4 | null |
|
||||
* | Elite EDC1.5 | DEF_ELITE_EDC_15 | Elite1.5 Dec. 2019 | Elite1.5 Dec. 2019 | 0, 2, 1, 6 | "Elite-EDC" | Elite_EDC_1.5 | EliteEDC |
|
||||
* | Elite EDC1.5re | DEF_ELITE_EDC_15RE | Elite1.5 Dec. 2019 | Elite1.5-re Jan. 2021 | 0, 2, 1, 7 | "Elite-EDC" | Elite_EDC_1.5re | EliteEDC |
|
||||
* | Elite EDC1.5r2 | DEF_ELITE_EDC_15R2 | Elite1.5 Dec. 2019 | Elite1.5-r2 May. 2022 | 0, 2, 1, 8 | "Elite-EDC" | Elite_EDC_1.5r2 | EliteEDC |
|
||||
* | Elite BAT0.1 | DEF_ELITE_BAT_01 | Elite2.0 Feb. 2022 | 0, 3, 1, 0 | "Elite-BAT" | Elite_BAT_0.1 | EliteEDC |
|
||||
* | Elite BAT1.0 | DEF_ELITE_BAT_10 | BAT SMC V1.0 Aug.2022| BAT PWR V1.0 Aug. 2022 | 0, 3, 1, 1 | "Elite-BAT" | Elite_BAT_1.0 | EliteEDC |
|
||||
* | Elite EIS1.0 | DEF_ELITE_EIS_10 | Elite1.5 Dec. 2019 | Elite EIS1.0 Aug. 2020 | 0, 4, 1, 0 | "Elite-EIS" | Elite_EIS_1.0 | EliteEIS |
|
||||
* | Elite EIS1.1 | DEF_ELITE_EIS_11 | Elite1.5 Dec. 2019 | Elite EIS1.1 Feb. 2022 | 0, 4, 1, 1 | "Elite-EIS" | Elite_EIS_1.1 | EliteEIS |
|
||||
* | Elite EISmini1.0 | DEF_ELITE_EIS_MINI_10 | EIS MINI May. 2022 | 0, 4, 1, 2 | "Elite-EIS-MINI" | Elite_EIS_MINI_1.0 | EliteEIS |
|
||||
* | Elite TRIG0.1 | DEF_ELITE_TRIG_01 | Elite TRIG01 Jan. 2021 | 0, 5, 1, 0 | "Elite-TRIG" | Elite_TRIG_0.1 | EliteTrigger |
|
||||
* | Elite MEGAFLY0.1 | DEF_ELITE_MEGAFLY_01 | Elite1.5 Dec. 2019 | Elite Megafly Sep. 2020 | 0, 6, 1, 0 | "Elite-MEGAFLY" | Elite_MEGAFLY_0.1 | null |
|
||||
* |-----------------+------------------------+----------------------+-------------------------+----------------+----------------------+----------------------+----------+
|
||||
* ps.
|
||||
* model name is FW engineer defined
|
||||
* device name is used for controller
|
||||
*/
|
||||
|
||||
|
||||
#define DEF_ELITE_EDC_14 0
|
||||
#define DEF_ELITE_EDC_15 1
|
||||
#define DEF_ELITE_EDC_15RE 2
|
||||
#define DEF_ELITE_EDC_15R2 3
|
||||
#define DEF_ELITE_BAT_01 4
|
||||
#define DEF_ELITE_BAT_10 5
|
||||
#define DEF_ELITE_EIS_10 6
|
||||
#define DEF_ELITE_EIS_11 7
|
||||
#define DEF_ELITE_EIS_MINI_10 8
|
||||
#define DEF_ELITE_TRIG_01 9
|
||||
#define DEF_ELITE_MEGAFLY_01 10
|
||||
#define DEF_ELITE_MAX 11
|
||||
|
||||
#define DEF_ELITE_MODEL DEF_ELITE_BAT_10
|
||||
#ifndef DEF_ELITE_MODEL
|
||||
#error "DEF_ELITE_MODEL not defined"
|
||||
#endif
|
||||
|
||||
// model information
|
||||
#if (DEF_ELITE_MODEL == DEF_ELITE_EDC_14)
|
||||
#error "code no support"
|
||||
#elif (DEF_ELITE_MODEL == DEF_ELITE_EDC_15)
|
||||
#error "code no support"
|
||||
#elif (DEF_ELITE_MODEL == DEF_ELITE_EDC_15RE)
|
||||
#error "code no support"
|
||||
#elif (DEF_ELITE_MODEL == DEF_ELITE_EDC_15R2)
|
||||
#error "code no support"
|
||||
#elif (DEF_ELITE_MODEL == DEF_ELITE_BAT_01)
|
||||
#error "code no support"
|
||||
#elif (DEF_ELITE_MODEL == DEF_ELITE_BAT_10)
|
||||
#include "BAT_10_conf.h"
|
||||
#elif (DEF_ELITE_MODEL == DEF_ELITE_EIS_10)
|
||||
#error "code no support"
|
||||
#elif (DEF_ELITE_MODEL == DEF_ELITE_EIS_11)
|
||||
#error "code no support"
|
||||
#elif (DEF_ELITE_MODEL == DEF_ELITE_EIS_MINI_10)
|
||||
#error "code no support"
|
||||
#elif (DEF_ELITE_MODEL == DEF_ELITE_TRIG_01)
|
||||
#error "code no support"
|
||||
#elif (DEF_ELITE_MODEL == DEF_ELITE_MEGAFLY_01)
|
||||
#error "code no support"
|
||||
#else
|
||||
#error "no this model"
|
||||
#endif
|
||||
|
||||
|
||||
// model information
|
||||
// #if (DEF_ELITE_MODEL == DEF_ELITE_EDC_14)
|
||||
// #define DEVICE_NAME "Elite-EDC"
|
||||
// #define MAJOR_PRODUCT_NUMBER 0
|
||||
// #define MINOR_PRODUCT_NUMBER 2
|
||||
// #define MAJOR_VERSION_NUMBER 1
|
||||
// #define MINOR_VERSION_NUMBER 5
|
||||
// #elif (DEF_ELITE_MODEL == DEF_ELITE_EDC_15)
|
||||
// #define DEVICE_NAME "Elite-EDC"
|
||||
// #define MAJOR_PRODUCT_NUMBER 0
|
||||
// #define MINOR_PRODUCT_NUMBER 2
|
||||
// #define MAJOR_VERSION_NUMBER 1
|
||||
// #define MINOR_VERSION_NUMBER 6
|
||||
// #elif (DEF_ELITE_MODEL == DEF_ELITE_EDC_15RE)
|
||||
// #define DEVICE_NAME "Elite-EDC"
|
||||
// #define MAJOR_PRODUCT_NUMBER 0
|
||||
// #define MINOR_PRODUCT_NUMBER 2
|
||||
// #define MAJOR_VERSION_NUMBER 1
|
||||
// #define MINOR_VERSION_NUMBER 7
|
||||
// #elif (DEF_ELITE_MODEL == DEF_ELITE_EDC_15R2)
|
||||
// #define DEVICE_NAME "Elite-EDC"
|
||||
// #define MAJOR_PRODUCT_NUMBER 0
|
||||
// #define MINOR_PRODUCT_NUMBER 2
|
||||
// #define MAJOR_VERSION_NUMBER 1
|
||||
// #define MINOR_VERSION_NUMBER 8
|
||||
// #elif (DEF_ELITE_MODEL == DEF_ELITE_BAT_01)
|
||||
// #define DEVICE_NAME "Elite-BAT"
|
||||
// #define MAJOR_PRODUCT_NUMBER 0
|
||||
// #define MINOR_PRODUCT_NUMBER 3
|
||||
// #define MAJOR_VERSION_NUMBER 1
|
||||
// #define MINOR_VERSION_NUMBER 0
|
||||
// #elif (DEF_ELITE_MODEL == DEF_ELITE_BAT_10)
|
||||
// #define DEVICE_NAME "Elite-BAT"
|
||||
// #define MAJOR_PRODUCT_NUMBER 0
|
||||
// #define MINOR_PRODUCT_NUMBER 3
|
||||
// #define MAJOR_VERSION_NUMBER 1
|
||||
// #define MINOR_VERSION_NUMBER 1
|
||||
// #elif (DEF_ELITE_MODEL == DEF_ELITE_EIS_10)
|
||||
// #define DEVICE_NAME "Elite-EIS"
|
||||
// #define MAJOR_PRODUCT_NUMBER 0
|
||||
// #define MINOR_PRODUCT_NUMBER 4
|
||||
// #define MAJOR_VERSION_NUMBER 1
|
||||
// #define MINOR_VERSION_NUMBER 0
|
||||
// #elif (DEF_ELITE_MODEL == DEF_ELITE_EIS_11)
|
||||
// #define DEVICE_NAME "Elite-EIS"
|
||||
// #define MAJOR_PRODUCT_NUMBER 0
|
||||
// #define MINOR_PRODUCT_NUMBER 4
|
||||
// #define MAJOR_VERSION_NUMBER 1
|
||||
// #define MINOR_VERSION_NUMBER 1
|
||||
// #elif (DEF_ELITE_MODEL == DEF_ELITE_EIS_MINI_10)
|
||||
// #define DEVICE_NAME "Elite-EIS"
|
||||
// #define MAJOR_PRODUCT_NUMBER 0
|
||||
// #define MINOR_PRODUCT_NUMBER 4
|
||||
// #define MAJOR_VERSION_NUMBER 1
|
||||
// #define MINOR_VERSION_NUMBER 2
|
||||
// #elif (DEF_ELITE_MODEL == DEF_ELITE_TRIG_01)
|
||||
// #define DEVICE_NAME "Elite-TRIG"
|
||||
// #define MAJOR_PRODUCT_NUMBER 0
|
||||
// #define MINOR_PRODUCT_NUMBER 5
|
||||
// #define MAJOR_VERSION_NUMBER 1
|
||||
// #define MINOR_VERSION_NUMBER 0
|
||||
// #elif (DEF_ELITE_MODEL == DEF_ELITE_MEGAFLY_01)
|
||||
// #define DEVICE_NAME "Elite-MEGAFLY"
|
||||
// #define MAJOR_PRODUCT_NUMBER 0
|
||||
// #define MINOR_PRODUCT_NUMBER 6
|
||||
// #define MAJOR_VERSION_NUMBER 1
|
||||
// #define MINOR_VERSION_NUMBER 0
|
||||
// #else
|
||||
// #error "no this model"
|
||||
// #endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
@@ -3,9 +3,9 @@
|
||||
#define VERSION_DATE
|
||||
|
||||
#define VERSION_DATE_YEAR 23
|
||||
#define VERSION_DATE_MONTH 3
|
||||
#define VERSION_DATE_DAY 15
|
||||
#define VERSION_DATE_HOUR 10
|
||||
#define VERSION_DATE_MONTH 12
|
||||
#define VERSION_DATE_DAY 4
|
||||
#define VERSION_DATE_HOUR 16
|
||||
#define VERSION_DATE_MINUTE 46
|
||||
|
||||
// this is NOT the version hash !!
|
||||
|
||||
@@ -1,975 +0,0 @@
|
||||
/*
|
||||
* Real instruction(RIS)
|
||||
* 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
||||
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
* | 0011 |Mem id| Payload len | Payload ...
|
||||
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
* ... ... |
|
||||
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
* Bytestream:
|
||||
* 34 0C 01 61 A8 75 30 03 E8 12 43 21 03 E8
|
||||
* 34 03 E1 01 03
|
||||
*
|
||||
*
|
||||
* Virtual instruction(VIS)
|
||||
* 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
|
||||
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
* | 1100 |Mem id| operation |
|
||||
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
* Bytestream:
|
||||
* C4 C0
|
||||
* C4 60
|
||||
*
|
||||
*
|
||||
* Control instruction(CIS)
|
||||
* 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
|
||||
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
* | 0111 |Mem id| operation |
|
||||
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
* Bytestream:
|
||||
* 74 40
|
||||
* 74 10
|
||||
*/
|
||||
|
||||
/*
|
||||
* RIS Payload
|
||||
* +----------------------------------+-------------------------------+
|
||||
* | mode(1B) | ... ... |
|
||||
* +----------------------------------+-------------------------------+
|
||||
* | CURVE_IV = 0x01 | ... ... |
|
||||
* | CURVE_IV_CY = 0x02 | ... ... |
|
||||
* | CURVE_VO = 0x03 | ... ... |
|
||||
* | CURVE_RT = 0x04 | ... ... |
|
||||
* | CURVE_VT = 0x05 | ... ... |
|
||||
* | CURVE_IT = 0x06 | ... ... |
|
||||
* | CURVE_CC = 0x07 | ... ... |
|
||||
* | CURVE_OCP = 0x08 | ... ... |
|
||||
* | CURVE_CV = 0x09 | ... ... |
|
||||
* | CURVE_LSV = 0x0A | ... ... |
|
||||
* | CURVE_CA = 0x0B | ... ... |
|
||||
* | CURVE_PULSE = 0x0C | ... ... |
|
||||
* | CURVE_UNI_PULSE = 0x0D | ... ... |
|
||||
* | CURVE_DPV = 0x0E | ... ... |
|
||||
* | CURVE_DPV_SMPRATE = 0x0F | ... ... |
|
||||
* | CURVE_DPV_ADVANCE = 0x10 | ... ... |
|
||||
* | CURVE_DPV_ADVANCE_SMPRATE = 0x11 | ... ... |
|
||||
* | CURVE_CALI_ADC = 0xF1 | ... ... |
|
||||
* | MODE_DEV_TOOL = 0xFF | ... ... |
|
||||
* | SET_SAMPLE_RATE = 0xE0 | ... ... |
|
||||
* | SET_ADC_DAC_GAIN = 0xE1 | ... ... |
|
||||
* | SET_PARA = 0xE2 | ... ... |
|
||||
* +----------------------------------+----------------------------------
|
||||
*/
|
||||
|
||||
static uint32_t OldStep2NewStepTime(uint32_t StepTime){
|
||||
uint8_t StepTimeLevel = 0;
|
||||
StepTimeLevel = StepTime / 0x12;
|
||||
|
||||
switch (StepTimeLevel) {
|
||||
case 0: { //0.5 sec
|
||||
return STEPTIME_HALF_SEC;
|
||||
}
|
||||
case 1: { //1 sec
|
||||
return STEPTIME_ONE_SEC;
|
||||
}
|
||||
case 2: { //2 sec
|
||||
return STEPTIME_TWO_SEC;
|
||||
}
|
||||
default: { //1 sec
|
||||
return STEPTIME_ONE_SEC;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#define STEP_TO_VSETRATE(step) step2VsetRate(step)
|
||||
|
||||
static void step2VsetRate(uint32_t step){
|
||||
/*step = 100 mv, index = 0, n = 2
|
||||
10 mv, index = 1, n = 10
|
||||
1 mv, index = 2, n = 100
|
||||
0.1 mv, index = 3, n = 1000
|
||||
0.01mv, index = 4, n = 10000 */
|
||||
|
||||
if(step >= 10000){
|
||||
instru.VsetRateIndex = 0;
|
||||
}else if (step >= 1000){
|
||||
instru.VsetRateIndex = 1;
|
||||
}else if (step >= 100){
|
||||
instru.VsetRateIndex = 2;
|
||||
}else if (step >= 10){
|
||||
instru.VsetRateIndex = 3;
|
||||
}else if (step >= 1){
|
||||
instru.VsetRateIndex = 4;
|
||||
}
|
||||
}
|
||||
|
||||
#include "headstage/mode_dev_tool.h"
|
||||
static void ins_decode_ris(uint8_t *ins_buf)
|
||||
{
|
||||
uint8_t *p = ins_buf;
|
||||
uint8_t mode = p[2];
|
||||
|
||||
switch (mode) {
|
||||
case CURVE_IV: {
|
||||
instru.eliteFxn = CURVE_IV;
|
||||
instru.Ve1 = ((uint16_t)(p[3]) << 8) | (uint16_t)(p[4]);
|
||||
instru.Ve2 = ((uint16_t)(p[5]) << 8) | (uint16_t)(p[6]);
|
||||
instru.Vinit = (int32_t)instru.Ve1;
|
||||
instru.Vmax = (int32_t)VMAX(instru.Ve1,instru.Ve2);
|
||||
instru.Vmin = (int32_t)VMIN(instru.Ve1,instru.Ve2);
|
||||
instru.directionInit = VDIRECTION(instru.Ve1,instru.Ve2);
|
||||
instru.steptime = (uint32_t)(p[9]);
|
||||
instru.steptime = OldStep2NewStepTime(instru.steptime); //5000;10000;20000;
|
||||
instru.step = ((uint32_t)(p[7]) << 8) | (uint32_t)(p[8]);//1~1000 = 0.1mv ~ 100mv
|
||||
instru.step = instru.step * 100000 / instru.steptime;
|
||||
STEP_TO_VSETRATE(instru.step);
|
||||
instru.VsetRate = VsetRateTable[instru.VsetRateIndex];//N
|
||||
instru.cycleNumber = 1;
|
||||
instru.hign_z_en = ~(p[11] & 0x0F);
|
||||
instru.notifyRate = ((uint32_t)p[12] << 8) | (uint32_t)p[13];
|
||||
instru.notifyRate = 10000 / instru.notifyRate * 10;
|
||||
|
||||
if ((instru.Ve1 < DAC_VOUT_GAIN_LARGE_BOUNDARY_USERCODE && instru.Ve1 > DAC_VOUT_GAIN_LARGE_BOUNDARY1_USERCODE)
|
||||
&& (instru.Ve2 < DAC_VOUT_GAIN_LARGE_BOUNDARY_USERCODE && instru.Ve2 > DAC_VOUT_GAIN_LARGE_BOUNDARY1_USERCODE)) {
|
||||
instru.VoutGainLv = VOUT_GAIN_15K;
|
||||
} else {
|
||||
instru.VoutGainLv = VOUT_GAIN_240K;
|
||||
}
|
||||
|
||||
ModeLED(WORKING);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case CURVE_IV_CY: {
|
||||
instru.eliteFxn = CURVE_IV_CY;
|
||||
instru.Ve1 = ((uint16_t)(p[3]) << 8) | (uint16_t)(p[4]);
|
||||
instru.Ve2 = ((uint16_t)(p[5]) << 8) | (uint16_t)(p[6]);
|
||||
instru.Vinit = (int32_t)instru.Ve1;
|
||||
instru.Vmax = (int32_t)VMAX(instru.Ve1,instru.Ve2);
|
||||
instru.Vmin = (int32_t)VMIN(instru.Ve1,instru.Ve2);
|
||||
instru.directionInit = VDIRECTION(instru.Ve1,instru.Ve2);
|
||||
instru.steptime = (uint32_t)(p[9]);
|
||||
instru.steptime = OldStep2NewStepTime(instru.steptime); //5000;10000;20000;
|
||||
instru.step = ((uint32_t)(p[7]) << 8) | (uint32_t)(p[8]);//1~1000 = 0.1mv ~ 100mv
|
||||
instru.step = instru.step * 100000 / instru.steptime;
|
||||
STEP_TO_VSETRATE(instru.step);
|
||||
instru.VsetRate = VsetRateTable[instru.VsetRateIndex];//N
|
||||
instru.cycleNumber = ((uint16_t)(p[10]) << 8) | (uint16_t)(p[11]);
|
||||
instru.hign_z_en = ~(p[13] & 0x0F);
|
||||
instru.notifyRate = ((uint32_t)p[14] << 8) | (uint32_t)p[15];
|
||||
instru.notifyRate = 10000 / instru.notifyRate * 10;
|
||||
|
||||
if ((instru.Ve1 < DAC_VOUT_GAIN_LARGE_BOUNDARY_USERCODE && instru.Ve1 > DAC_VOUT_GAIN_LARGE_BOUNDARY1_USERCODE)
|
||||
&& (instru.Ve2 < DAC_VOUT_GAIN_LARGE_BOUNDARY_USERCODE && instru.Ve2 > DAC_VOUT_GAIN_LARGE_BOUNDARY1_USERCODE)) {
|
||||
instru.VoutGainLv = VOUT_GAIN_15K;
|
||||
} else {
|
||||
instru.VoutGainLv = VOUT_GAIN_240K;
|
||||
}
|
||||
|
||||
ModeLED(WORKING);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case CURVE_VO: {
|
||||
instru.eliteFxn = CURVE_VO;
|
||||
instru.Ve1 = ((uint16_t)p[3] << 8) | (uint16_t)p[4];
|
||||
instru.Vinit = (int32_t)instru.Ve1;
|
||||
instru.hign_z_en = ~(p[6] & 0x0F);
|
||||
|
||||
if (instru.Ve1 < DAC_VOUT_GAIN_LARGE_BOUNDARY_USERCODE && instru.Ve1 > DAC_VOUT_GAIN_LARGE_BOUNDARY1_USERCODE) {
|
||||
instru.VoutGainLv = VOUT_GAIN_15K;
|
||||
} else {
|
||||
instru.VoutGainLv = VOUT_GAIN_240K;
|
||||
}
|
||||
|
||||
instru.notifyRate = ((uint32_t)p[7] << 8) | (uint32_t)p[8];
|
||||
instru.notifyRate = 10000 / instru.notifyRate * 10;
|
||||
|
||||
ModeLED(WORKING);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case CURVE_RT: {
|
||||
instru.eliteFxn = CURVE_RT;
|
||||
instru.notifyRate = ((uint32_t)p[7] << 8) | (uint32_t)p[8];
|
||||
instru.notifyRate = 10000 / instru.notifyRate * 10;
|
||||
instru.VsetRate = 2;
|
||||
instru.Ve1 = ((uint16_t)p[3] << 8) | (uint16_t)p[4];
|
||||
instru.Vinit = (int32_t)instru.Ve1;
|
||||
instru.hign_z_en = ~(p[6] & 0x0F);
|
||||
|
||||
if (instru.Ve1 < DAC_VOUT_GAIN_LARGE_BOUNDARY_USERCODE && instru.Ve1 > DAC_VOUT_GAIN_LARGE_BOUNDARY1_USERCODE) {
|
||||
instru.VoutGainLv = VOUT_GAIN_15K;
|
||||
} else {
|
||||
instru.VoutGainLv = VOUT_GAIN_240K;
|
||||
}
|
||||
|
||||
ModeLED(WORKING);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case CURVE_VT: {
|
||||
instru.eliteFxn = CURVE_VT;
|
||||
instru.notifyRate = ((uint32_t)p[5] << 8) | (uint32_t)p[6];
|
||||
instru.notifyRate = 10000 / instru.notifyRate * 10;
|
||||
instru.hign_z_en = ~(p[4] & 0x0F);
|
||||
|
||||
ModeLED(WORKING);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case CURVE_IT: {
|
||||
instru.eliteFxn = CURVE_IT;
|
||||
instru.notifyRate = ((uint32_t)p[7] << 8) | (uint32_t)p[8];
|
||||
instru.notifyRate = 10000 / instru.notifyRate * 10;
|
||||
instru.Ve1 = ((uint16_t)p[3] << 8) | (uint16_t)p[4];
|
||||
instru.Vinit = (int32_t)instru.Ve1;
|
||||
instru.hign_z_en = ~(p[6] & 0x0F);
|
||||
|
||||
if (instru.Ve1 < DAC_VOUT_GAIN_LARGE_BOUNDARY_USERCODE && instru.Ve1 > DAC_VOUT_GAIN_LARGE_BOUNDARY1_USERCODE) {
|
||||
instru.VoutGainLv = VOUT_GAIN_15K;
|
||||
} else {
|
||||
instru.VoutGainLv = VOUT_GAIN_240K;
|
||||
}
|
||||
|
||||
ModeLED(WORKING);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case CURVE_CC: {
|
||||
instru.eliteFxn = CURVE_CC;
|
||||
instru.notifyRate = ((uint32_t)p[14] << 8) | (uint32_t)p[15];
|
||||
instru.notifyRate = 10000 / instru.notifyRate * 10;
|
||||
instru.charge = p[3]; //0:discharge 1:charge
|
||||
instru.constantCurrent = (uint32_t)(p[4]) << 24 | (uint32_t)(p[5]) << 16 | (uint32_t)(p[6]) << 8 | (uint32_t)(p[7]);
|
||||
instru.Vmax = (uint32_t)(p[8]) << 8 | (uint32_t)(p[9]);
|
||||
instru.Vmin = (uint32_t)(p[10]) << 8 | (uint32_t)(p[11]);
|
||||
instru.hign_z_en = ~(p[13] & 0x0F);
|
||||
|
||||
instru.VoutGainLv = VOUT_GAIN_240K;
|
||||
|
||||
ModeLED(WORKING);
|
||||
/*******************************************************
|
||||
controller instruction
|
||||
p[3] -> Charge, 0:discharge 1:charge
|
||||
p[6:9] -> ConstantCurrent, 0 ~ 15000uA : 0 ~ 1500000
|
||||
********************************************************/
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case CURVE_CV: {
|
||||
if (p[3] == PARA_1) {
|
||||
instru.Vinit = ((int32_t)(p[4]) << 8) | (int32_t)(p[5]);
|
||||
instru.Ve1 = ((uint16_t)(p[6]) << 8) | (uint16_t)(p[7]);
|
||||
instru.Ve2 = ((uint16_t)(p[8]) << 8) | (uint16_t)(p[9]);
|
||||
instru.Vmax = (int32_t)VMAX(instru.Ve1,instru.Ve2);
|
||||
instru.Vmin = (int32_t)VMIN(instru.Ve1,instru.Ve2);
|
||||
if (instru.Vinit > instru.Ve1 || instru.Vinit == instru.Vmax) {
|
||||
instru.directionInit = 0;//0:reverse 1:forward
|
||||
} else if (instru.Vinit <= instru.Ve1 || instru.Vinit == instru.Vmin) {
|
||||
instru.directionInit = 1;
|
||||
}
|
||||
|
||||
//controller UI 0.01~1000mv send to Elite 1~100000
|
||||
instru.step = (uint32_t)(p[10]) << 24 | (uint32_t)(p[11]) << 16 | (uint32_t)(p[12]) << 8 | (uint32_t)(p[13]);
|
||||
STEP_TO_VSETRATE(instru.step);
|
||||
instru.VsetRate = VsetRateTable[instru.VsetRateIndex];//N
|
||||
|
||||
instru.Currentmax = (int32_t)(p[14]) << 24 | (int32_t)(p[15]) << 16 | (int32_t)(p[16]) << 8 | (int32_t)(p[17]);
|
||||
|
||||
} else if (p[3] == PARA_2) {
|
||||
instru.eliteFxn = CURVE_CV;
|
||||
instru.cycleNumber = ((uint16_t)(p[4]) << 8) | (uint16_t)(p[5]);
|
||||
instru.notifyRate = (uint32_t)(p[8]) << 8 | (uint32_t)(p[9]);
|
||||
instru.notifyRate = 10000 / instru.notifyRate * 10;
|
||||
instru.hign_z_en = ~(p[7] & 0x0F);
|
||||
|
||||
instru.VoutGainLv = VOUT_GAIN_240K;
|
||||
ModeLED(WORKING);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case CURVE_LSV: {
|
||||
if (p[3] == PARA_1) {
|
||||
instru.Ve1 = ((uint16_t)(p[4]) << 8) | (uint16_t)(p[5]);
|
||||
instru.Ve2 = ((uint16_t)(p[6]) << 8) | (uint16_t)(p[7]);
|
||||
instru.Vinit = (int32_t)instru.Ve1;
|
||||
instru.Vmax = (int32_t)VMAX(instru.Ve1,instru.Ve2);
|
||||
instru.Vmin = (int32_t)VMIN(instru.Ve1,instru.Ve2);
|
||||
instru.directionInit = VDIRECTION(instru.Ve1,instru.Ve2);
|
||||
instru.Currentmax = (int32_t)(p[12]) << 24 | (int32_t)(p[13]) << 16 | (int32_t)(p[14]) << 8 | (int32_t)(p[15]);
|
||||
|
||||
//controller UI 0.01~1000mv send to Elite 1~100000
|
||||
instru.step = (uint32_t)(p[8]) << 24 | (uint32_t)(p[9]) << 16 | (uint32_t)(p[10]) << 8 | (uint32_t)(p[11]);
|
||||
STEP_TO_VSETRATE(instru.step);
|
||||
instru.VsetRate = VsetRateTable[instru.VsetRateIndex];//N
|
||||
instru.cycleNumber = 1;//p[16.17];
|
||||
|
||||
} else if (p[3] == PARA_2) {
|
||||
instru.eliteFxn = CURVE_LSV;
|
||||
instru.notifyRate = (uint32_t)(p[6]) << 8 | (uint32_t)(p[7]);
|
||||
instru.notifyRate = 10000 / instru.notifyRate * 10;
|
||||
instru.hign_z_en = ~(p[5] & 0x0F);
|
||||
|
||||
instru.VoutGainLv = VOUT_GAIN_240K;
|
||||
|
||||
ModeLED(WORKING);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case CURVE_CA: {
|
||||
instru.eliteFxn = CURVE_CA;
|
||||
instru.Vinit = ((int32_t)(p[3]) << 8) | (int32_t)(p[4]);
|
||||
instru.notifyRate = (uint32_t)(p[7]) << 8 | (uint32_t)(p[8]);
|
||||
instru.notifyRate = 10000 / instru.notifyRate * 10;
|
||||
instru.VsetRate = VsetRateTable[0];
|
||||
instru.hign_z_en = ~(p[6] & 0x0F);
|
||||
|
||||
instru.VoutGainLv = VOUT_GAIN_240K;
|
||||
|
||||
ModeLED(WORKING);
|
||||
break;
|
||||
}
|
||||
|
||||
case CURVE_OCP: {
|
||||
instru.eliteFxn = CURVE_OCP;
|
||||
instru.notifyRate = ((uint32_t)p[5] << 8) | (uint32_t)p[6];
|
||||
instru.notifyRate = 10000 / instru.notifyRate * 10;
|
||||
instru.hign_z_en = 0;
|
||||
|
||||
ModeLED(WORKING);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case SET_SAMPLE_RATE: {
|
||||
instru.notifyRate = (uint32_t)(p[3]) << 8 | (uint32_t)(p[4]);
|
||||
instru.notifyRate = 10000 / instru.notifyRate * 10;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case SET_ADC_DAC_GAIN: {
|
||||
switch (p[3]) {
|
||||
case RIS_ADC_IIN: {
|
||||
instru.IinADCGainLv = p[4];
|
||||
if (instru.IinADCGainLv != I_GAIN_AUTO) {
|
||||
instru.IinADCAutoGainEn = 0;
|
||||
} else {
|
||||
instru.IinADCAutoGainEn = 1;
|
||||
instru.IinADCGainLv = I_GAIN_100R;
|
||||
IinADCGainCtrl(instru.IinADCGainLv);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case RIS_ADC_VIN: {
|
||||
instru.VinADCGainLv = p[4];
|
||||
if (instru.VinADCGainLv != VIN_GAIN_AUTO) {
|
||||
instru.VinADCAutoGainEn = 0;
|
||||
} else {
|
||||
instru.VinADCAutoGainEn = 1;
|
||||
instru.VinADCGainLv = VIN_GAIN_1K;
|
||||
VinADCGainCtrl(instru.VinADCGainLv);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case RIS_DAC_VOUT: {
|
||||
// instru.VoutGainLv = p[4];
|
||||
// if (instru.VoutGainLv == VOUT_GAIN_AUTO) {
|
||||
// instru.VoutGainLv = VOUT_GAIN_15K;
|
||||
// }
|
||||
instru.VoutGainLv = p[4];
|
||||
VoutGainControl(instru.VoutGainLv);
|
||||
break;
|
||||
}
|
||||
case RIS_HIGH_Z: {
|
||||
switch (p[4]) {
|
||||
case 0x00:
|
||||
PIN15_setOutputValue(HIGH_Z, 0); // 0 => open high_z mode
|
||||
break;
|
||||
|
||||
case 0x01:
|
||||
PIN15_setOutputValue(HIGH_Z, 1); // 1 => close high_z mode
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case CURVE_CALI_ADC: {
|
||||
switch (p[3]) {
|
||||
case RIS_ADC_IIN: { // 0x00
|
||||
instru.eliteFxn = CURVE_CALI_ADC;
|
||||
instru.AdcChannel = RIS_ADC_IIN;
|
||||
instru.notifyRate = 1000;
|
||||
ModeLED(WORKING);
|
||||
break;
|
||||
}
|
||||
case RIS_ADC_VIN: { // 0x01
|
||||
instru.eliteFxn = CURVE_CALI_ADC;
|
||||
instru.AdcChannel = RIS_ADC_VIN;
|
||||
instru.notifyRate = 1000;
|
||||
ModeLED(WORKING);
|
||||
break;
|
||||
}
|
||||
case RIS_DAC_VOUT: { // 0x02
|
||||
instru.eliteFxn = CURVE_CALI_ADC;
|
||||
instru.AdcChannel = RIS_DAC_VOUT;
|
||||
instru.notifyRate = 1000;
|
||||
instru.VoltConstant = ( ((uint16_t)(p[4])) << 8) | (uint16_t)(p[5]); // output voltage
|
||||
DAC_outputV(instru.VoltConstant); //UserCode -> DAC code -> DAC out
|
||||
ModeLED(WORKING);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case CURVE_PULSE: {
|
||||
instru.VoutGainLv = VOUT_GAIN_240K;
|
||||
instru.notifyRate = 100;
|
||||
if (p[3] == PARA_1) {
|
||||
instru.sti_t1 = (int32_t)(p[4]) << 24 | (int32_t)(p[5]) << 16 | (int32_t)(p[6]) << 8 | (int32_t)(p[7]);
|
||||
instru.sti_t2 = (int32_t)(p[8]) << 24 | (int32_t)(p[9]) << 16 | (int32_t)(p[10]) << 8 | (int32_t)(p[11]);
|
||||
instru.sti_t3 = (int32_t)(p[12]) << 24 | (int32_t)(p[13]) << 16 | (int32_t)(p[14]) << 8 | (int32_t)(p[15]);
|
||||
instru.sti_t4 = (int32_t)(p[16]) << 24 | (int32_t)(p[17]) << 16 | (int32_t)(p[18]) << 8 | (int32_t)(p[19]);
|
||||
} else if (p[3] == PARA_2) {
|
||||
instru.sti_t5 = (int32_t)(p[4]) << 24 | (int32_t)(p[5]) << 16 | (int32_t)(p[6]) << 8 | (int32_t)(p[7]);
|
||||
instru.sti_v1 = 25000; //8~11
|
||||
instru.sti_v2 = 50000; //12~15 //41406.43161.
|
||||
instru.sti_v3 = 25000; //16~19
|
||||
} else if (p[3] == PARA_3) {
|
||||
instru.sti_v4 = 25000; //4~7
|
||||
instru.sti_v5 = 25000; //8~11
|
||||
instru.sti_cy = (uint16_t)(p[12]); //12
|
||||
instru.sti_loop = (uint16_t)(p[13]); //13
|
||||
} else if (p[3] == PARA_4) {
|
||||
instru.sti_t6 = (int32_t)(p[4]) << 24 | (int32_t)(p[5]) << 16 | (int32_t)(p[6]) << 8 | (int32_t)(p[7]); //4~7
|
||||
instru.sti_t7 = (int32_t)(p[8]) << 24 | (int32_t)(p[9]) << 16 | (int32_t)(p[10]) << 8 | (int32_t)(p[11]); //8~11
|
||||
instru.sti_v6 = 25000; //12~15
|
||||
instru.sti_v7 = 25000; //16~19
|
||||
instru.sti_t1 = VALUE_ZERO_TO_ONE(instru.sti_t1);
|
||||
instru.sti_t2 = VALUE_ZERO_TO_ONE(instru.sti_t2);
|
||||
instru.sti_t3 = VALUE_ZERO_TO_ONE(instru.sti_t3);
|
||||
instru.sti_t4 = VALUE_ZERO_TO_ONE(instru.sti_t4);
|
||||
instru.sti_t5 = VALUE_ZERO_TO_ONE(instru.sti_t5);
|
||||
instru.sti_t6 = VALUE_ZERO_TO_ONE(instru.sti_t6);
|
||||
instru.sti_t7 = VALUE_ZERO_TO_ONE(instru.sti_t7);
|
||||
megaStiEnable = true;
|
||||
} else if (p[3] == PARA_17) {
|
||||
instru.eliteFxn = CURVE_PULSE;
|
||||
ModeLED(WORKING);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case CURVE_UNI_PULSE: {
|
||||
if (p[3] == PARA_1) {
|
||||
uint8_t seg_index = p[12];
|
||||
instru.v_initial[seg_index] = (int32_t)p[4] << 8 | (int32_t)p[5];
|
||||
instru.v0 = instru.v_initial[0];
|
||||
instru.t_pulse[seg_index] = (uint32_t)p[6] << 24 | (uint32_t)p[7] << 16 | (uint32_t)p[8] << 8 | (uint32_t)p[9];
|
||||
instru.t_pulse_min[seg_index] = (uint32_t)p[10];
|
||||
instru.t_pulse_max[seg_index] = (uint32_t)p[11];
|
||||
instru.v_slope[seg_index] = 0;
|
||||
instru.v_step[seg_index] = 0;
|
||||
|
||||
} else if (p[3] == PARA_2) {
|
||||
uint8_t seg_index = p[12];
|
||||
instru.v_initial[seg_index] = (int32_t)p[4] << 8 | (int32_t)p[5];
|
||||
instru.t_pulse[seg_index] = (uint32_t)p[6] << 24 | (uint32_t)p[7] << 16 | (uint32_t)p[8] << 8 | (uint32_t)p[9];
|
||||
instru.t_pulse_min[seg_index] = (uint32_t)p[10];
|
||||
instru.t_pulse_max[seg_index] = (uint32_t)p[11];
|
||||
instru.v_slope[seg_index] = 0;
|
||||
instru.v_step[seg_index] = 0;
|
||||
|
||||
} else if (p[3] == PARA_3) {
|
||||
uint8_t seg_index = p[12];
|
||||
instru.v_initial[seg_index] = (int32_t)p[4] << 8 | (int32_t)p[5];
|
||||
instru.t_pulse[seg_index] = (uint32_t)p[6] << 24 | (uint32_t)p[7] << 16 | (uint32_t)p[8] << 8 | (uint32_t)p[9];
|
||||
instru.t_pulse_min[seg_index] = (uint32_t)p[10];
|
||||
instru.t_pulse_max[seg_index] = (uint32_t)p[11];
|
||||
instru.v_slope[seg_index] = 0;
|
||||
instru.v_step[seg_index] = 0;
|
||||
|
||||
} else if (p[3] == PARA_4) {
|
||||
uint8_t seg_index = p[12];
|
||||
instru.v_initial[seg_index] = (int32_t)p[4] << 8 | (int32_t)p[5];
|
||||
instru.t_pulse[seg_index] = (uint32_t)p[6] << 24 | (uint32_t)p[7] << 16 | (uint32_t)p[8] << 8 | (uint32_t)p[9];
|
||||
instru.t_pulse_min[seg_index] = (uint32_t)p[10];
|
||||
instru.t_pulse_max[seg_index] = (uint32_t)p[11];
|
||||
instru.v_slope[seg_index] = 0;
|
||||
instru.v_step[seg_index] = 0;
|
||||
|
||||
} else if (p[3] == PARA_FINAL) {
|
||||
instru.eliteFxn = CURVE_UNI_PULSE;
|
||||
|
||||
instru.VoutGainLv = VOUT_GAIN_240K;
|
||||
|
||||
ModeLED(WORKING);
|
||||
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case CURVE_DPV: {
|
||||
|
||||
/*
|
||||
* DPV mode --auto
|
||||
* +----------+------------+-------------+-----------------+---------------+---------------+
|
||||
* | UI | E Initial | E Final | Pulse Amplitude | Pulse Width | Increment |
|
||||
* | json | DPV_e_init | DPV_e_final | DPV_amp | DPV_pul_width | DPV_increment |
|
||||
* +----------+------------+-------------+-----------------+---------------+---------------+
|
||||
* | UI | Step Time | Sample rate | (audio) | (audio) |
|
||||
* | json | DPV_step_time | DPV_notify_rate | DPV_mode | DPV_engineering_enable |
|
||||
* +----------+---------------+-----------------+----------+------------------------+
|
||||
* hide parameter
|
||||
* +----------+-------------------------------------+
|
||||
* | UI | Current Recording Period(Slots) |
|
||||
* | json | DPV_curr_rec_max | DPV_curr_rec_min |
|
||||
* +----------+------------------+------------------+
|
||||
*
|
||||
*/
|
||||
//--mode
|
||||
static uint8_t dpv_option;
|
||||
|
||||
//--Auto
|
||||
static int32_t dpv_e_init;
|
||||
static int32_t dpv_e_final;
|
||||
static int32_t dpv_amp;
|
||||
static uint32_t dpv_pul_width;
|
||||
static int32_t dpv_increment;
|
||||
static uint32_t dpv_step_time;
|
||||
static uint32_t dpv_notify_rate;
|
||||
static uint32_t dpv_curr_rec_percent_min[4];
|
||||
static uint32_t dpv_curr_rec_percent_max[4];
|
||||
|
||||
//--engineering
|
||||
static uint8_t dpv_engi_advanced_en;
|
||||
|
||||
if (p[3] == PARA_1) {
|
||||
dpv_option = p[4];
|
||||
dpv_engi_advanced_en = p[5];
|
||||
|
||||
} else if (p[3] == PARA_2) {
|
||||
dpv_e_init = (int32_t)p[4] << 8 | (int32_t)p[5];
|
||||
dpv_e_final = (int32_t)p[6] << 8 | (int32_t)p[7];
|
||||
dpv_amp = (int32_t)p[8] << 8 | (int32_t)p[9];
|
||||
dpv_pul_width = (uint32_t)p[10] << 24 | (uint32_t)p[11] << 16 | (uint32_t)p[12] << 8 | (uint32_t)p[13];
|
||||
dpv_increment = (int32_t)p[14] << 8 | (int32_t)p[15];
|
||||
|
||||
} else if (p[3] == PARA_3) {
|
||||
dpv_step_time = (uint32_t)p[4] << 24 | (uint32_t)p[5] << 16 | (uint32_t)p[6] << 8 | (uint32_t)p[7];
|
||||
dpv_notify_rate = (uint32_t)p[8] << 8 | (uint32_t)p[9];
|
||||
dpv_curr_rec_percent_min[0] = (uint32_t)p[10];
|
||||
dpv_curr_rec_percent_max[0] = (uint32_t)p[11];
|
||||
dpv_curr_rec_percent_min[1] = (uint32_t)p[10];
|
||||
dpv_curr_rec_percent_max[1] = (uint32_t)p[11];
|
||||
|
||||
} else if (p[3] == PARA_FINAL) {
|
||||
dpv_e_init = UC_TO_5NV(dpv_e_init);
|
||||
dpv_e_final = UC_TO_5NV(dpv_e_final);
|
||||
dpv_amp = UC_TO_5NV(dpv_amp);
|
||||
dpv_pul_width = dpv_pul_width * 10;
|
||||
dpv_increment = UC_TO_5NV(dpv_increment);
|
||||
dpv_increment = abs(dpv_increment);
|
||||
dpv_step_time = dpv_step_time * 10;
|
||||
dpv_notify_rate = 10000 / dpv_notify_rate * 10;
|
||||
|
||||
instru.v0 = dpv_e_init;
|
||||
instru.v_stop = dpv_e_final;
|
||||
instru.t_pulse[0] = dpv_step_time - dpv_pul_width;
|
||||
instru.t_pulse[1] = dpv_pul_width;
|
||||
instru.v_initial[0] = dpv_e_init;
|
||||
instru.v_initial[1] = dpv_e_init + dpv_amp;
|
||||
instru.v_step[0] = dpv_increment;
|
||||
instru.v_step[1] = dpv_increment;
|
||||
instru.notifyRate = dpv_notify_rate;
|
||||
instru.v_slope[0] = 0; // 1234 = slop 1.234, same as scanrate
|
||||
instru.v_slope[1] = 0; // 1234 = slop 1.234
|
||||
instru.t_pulse_min[0] = dpv_curr_rec_percent_min[0];
|
||||
instru.t_pulse_max[0] = dpv_curr_rec_percent_max[0];
|
||||
instru.t_pulse_min[1] = dpv_curr_rec_percent_min[1];
|
||||
instru.t_pulse_max[1] = dpv_curr_rec_percent_max[1];
|
||||
|
||||
if (instru.v0 > instru.v_stop) {
|
||||
instru.directionInit = 0;//0:reverse 1:forward
|
||||
instru.v_step[0] = (-1) * instru.v_step[0];
|
||||
instru.v_step[1] = (-1) * instru.v_step[1];
|
||||
} else if (instru.v0 < instru.v_stop) {
|
||||
instru.directionInit = 1;
|
||||
}
|
||||
|
||||
if (dpv_option == 0) {
|
||||
instru.eliteFxn = CURVE_DPV;
|
||||
} else if (dpv_option == 2) {
|
||||
instru.eliteFxn = CURVE_DPV_SMPRATE;
|
||||
}
|
||||
instru.VoutGainLv = VOUT_GAIN_240K;
|
||||
ModeLED(WORKING);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case CURVE_DPV_ADVANCE: {
|
||||
|
||||
/*
|
||||
* DPV mode --advanced
|
||||
* +----------+------------+---------+---------+-------------+-----------------+---------------+---------------+
|
||||
* | UI | E Initial | E 1 | E 2 | E Final | Pulse Amplitude | Pulse Width | Increment |
|
||||
* | json | DPV_e_init | DPV_e_1 | DPV_e_2 | DPV_e_final | DPV_amp | DPV_pul_width | DPV_increment |
|
||||
* +----------+------------+---------+---------+-------------+-----------------+---------------+---------------+
|
||||
* | UI | Step Time | Sample rate | Current Recording Period(Slots) |
|
||||
* | json | DPV_step_time | DPV_notify_rate | DPV_curr_rec_max | DPV_curr_rec_min |
|
||||
* +----------+---------------+-----------------+------------------+------------------+
|
||||
* | UI | (audio) | (audio) |
|
||||
* | json | DPV_mode | DPV_engineering_enable |
|
||||
* +----------+----------+------------------------+
|
||||
*
|
||||
*/
|
||||
//--mode
|
||||
static uint8_t dpv_option;
|
||||
|
||||
//--advanced
|
||||
static int32_t dpv_e_init;
|
||||
static int32_t dpv_e_final;
|
||||
static int32_t dpv_amp;
|
||||
static uint32_t dpv_pul_width;
|
||||
static int32_t dpv_increment;
|
||||
static uint32_t dpv_step_time;
|
||||
static uint32_t dpv_notify_rate;
|
||||
static uint32_t dpv_curr_rec_percent_min[4];
|
||||
static uint32_t dpv_curr_rec_percent_max[4];
|
||||
static int32_t dpv_e_1;
|
||||
static int32_t dpv_e_2;
|
||||
static uint8_t dpv_invert_option;
|
||||
static uint16_t dpv_cycle;
|
||||
|
||||
//--engineering
|
||||
static uint8_t dpv_engi_advanced_en;
|
||||
|
||||
if (p[3] == PARA_1) {
|
||||
dpv_option = p[4];
|
||||
dpv_engi_advanced_en = p[5];
|
||||
|
||||
} else if (p[3] == PARA_2) {
|
||||
dpv_e_init = (int32_t)p[4] << 8 | (int32_t)p[5];
|
||||
dpv_e_final = (int32_t)p[6] << 8 | (int32_t)p[7];
|
||||
dpv_amp = (int32_t)p[8] << 8 | (int32_t)p[9];
|
||||
dpv_pul_width = (uint32_t)p[10] << 24 | (uint32_t)p[11] << 16 | (uint32_t)p[12] << 8 | (uint32_t)p[13];
|
||||
dpv_increment = (int32_t)p[14] << 8 | (int32_t)p[15];
|
||||
|
||||
} else if (p[3] == PARA_3) {
|
||||
dpv_step_time = (uint32_t)p[4] << 24 | (uint32_t)p[5] << 16 | (uint32_t)p[6] << 8 | (uint32_t)p[7];
|
||||
dpv_notify_rate = (uint32_t)p[8] << 8 | (uint32_t)p[9];
|
||||
dpv_curr_rec_percent_min[0] = (uint32_t)p[10];
|
||||
dpv_curr_rec_percent_max[0] = (uint32_t)p[11];
|
||||
dpv_curr_rec_percent_min[1] = (uint32_t)p[10];
|
||||
dpv_curr_rec_percent_max[1] = (uint32_t)p[11];
|
||||
|
||||
} else if (p[3] == PARA_4) {
|
||||
dpv_e_1 = (int32_t)p[4] << 8 | (int32_t)p[5];
|
||||
dpv_e_2 = (int32_t)p[6] << 8 | (int32_t)p[7];
|
||||
dpv_invert_option = p[8];
|
||||
dpv_cycle = (uint16_t)p[9] << 8 | (uint16_t)p[10];
|
||||
|
||||
} else if (p[3] == PARA_FINAL) {
|
||||
dpv_e_init = UC_TO_5NV(dpv_e_init);
|
||||
dpv_e_final = UC_TO_5NV(dpv_e_final);
|
||||
dpv_amp = UC_TO_5NV(dpv_amp);
|
||||
dpv_pul_width = dpv_pul_width * 10;
|
||||
dpv_increment = UC_TO_5NV(dpv_increment);
|
||||
dpv_increment = abs(dpv_increment);
|
||||
dpv_step_time = dpv_step_time * 10;
|
||||
dpv_notify_rate = 10000 / dpv_notify_rate * 10;
|
||||
dpv_e_1 = UC_TO_5NV(dpv_e_1);
|
||||
dpv_e_2 = UC_TO_5NV(dpv_e_2);
|
||||
|
||||
instru.v0 = dpv_e_init;
|
||||
instru.v_stop = dpv_e_final;
|
||||
instru.t_pulse[0] = dpv_step_time - dpv_pul_width;
|
||||
instru.t_pulse[1] = dpv_pul_width;
|
||||
instru.v_initial[0] = dpv_e_init;
|
||||
instru.v_initial[1] = dpv_e_init + dpv_amp;
|
||||
instru.v_step[0] = abs(dpv_increment);
|
||||
instru.v_step[1] = abs(dpv_increment);
|
||||
instru.notifyRate = dpv_notify_rate;
|
||||
instru.v_slope[0] = 0; // 1234 = slop 1.234, same as scanrate
|
||||
instru.v_slope[1] = 0; // 1234 = slop 1.234
|
||||
instru.t_pulse_min[0] = dpv_curr_rec_percent_min[0];
|
||||
instru.t_pulse_max[0] = dpv_curr_rec_percent_max[0];
|
||||
instru.t_pulse_min[1] = dpv_curr_rec_percent_min[1];
|
||||
instru.t_pulse_max[1] = dpv_curr_rec_percent_max[1];
|
||||
instru.v_1 = dpv_e_1;
|
||||
instru.v_2 = dpv_e_2;
|
||||
instru.cycleNumber = dpv_cycle;
|
||||
if (dpv_invert_option == 1) {
|
||||
instru.v_invert_option = true;
|
||||
} else {
|
||||
instru.v_invert_option = false;
|
||||
}
|
||||
|
||||
|
||||
if (instru.v0 > dpv_e_1) {
|
||||
instru.directionInit = 0;//0:reverse 1:forward
|
||||
instru.v_step[0] = (-1) * instru.v_step[0];
|
||||
instru.v_step[1] = (-1) * instru.v_step[1];
|
||||
|
||||
} else if (instru.v0 < dpv_e_1) {
|
||||
instru.directionInit = 1;
|
||||
|
||||
}
|
||||
|
||||
if (dpv_e_1 > dpv_e_2) {
|
||||
instru.v_up = dpv_e_1;
|
||||
instru.v_low = dpv_e_2;
|
||||
instru.v_stop_direction = 1;//0:reverse 1:forward
|
||||
|
||||
} else if (dpv_e_1 < dpv_e_2) {
|
||||
instru.v_up = dpv_e_2;
|
||||
instru.v_low = dpv_e_1;
|
||||
instru.v_stop_direction = 0;//0:reverse 1:forward
|
||||
}
|
||||
|
||||
if (dpv_option == 1) {
|
||||
instru.eliteFxn = CURVE_DPV_ADVANCE;
|
||||
} else if (dpv_option == 2) {
|
||||
instru.eliteFxn = CURVE_DPV_ADVANCE_SMPRATE;
|
||||
}
|
||||
instru.VoutGainLv = VOUT_GAIN_240K;
|
||||
ModeLED(WORKING);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case SET_PARA: {
|
||||
int32_t value;
|
||||
|
||||
if (instru.eliteFxn == CURVE_VO) {
|
||||
switch (p[3]) {
|
||||
case DAC_VOLT:
|
||||
value = (p[4] << 8) | p[5]; // usercode
|
||||
|
||||
if (value < DAC_VOUT_GAIN_LARGE_BOUNDARY_USERCODE && value > DAC_VOUT_GAIN_LARGE_BOUNDARY1_USERCODE) {
|
||||
instru.VoutGainLv = VOUT_GAIN_15K;
|
||||
} else {
|
||||
instru.VoutGainLv = VOUT_GAIN_240K;
|
||||
}
|
||||
VoutGainControl(instru.VoutGainLv);
|
||||
|
||||
value = (value - 25000) * 4 * 10000; //[5nV]
|
||||
set_para(instru.eliteFxn, DAC_VOLT, value);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
} else if (instru.eliteFxn == CURVE_IT) {
|
||||
switch (p[3]) {
|
||||
case DAC_VOLT:
|
||||
value = (p[4] << 8) | p[5]; // usercode
|
||||
|
||||
if (value < DAC_VOUT_GAIN_LARGE_BOUNDARY_USERCODE && value > DAC_VOUT_GAIN_LARGE_BOUNDARY1_USERCODE) {
|
||||
instru.VoutGainLv = VOUT_GAIN_15K;
|
||||
} else {
|
||||
instru.VoutGainLv = VOUT_GAIN_240K;
|
||||
}
|
||||
VoutGainControl(instru.VoutGainLv);
|
||||
|
||||
value = (value - 25000) * 4 * 10000; //[5nV]
|
||||
set_para(instru.eliteFxn, DAC_VOLT, value);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
} else if (instru.eliteFxn == CURVE_RT) {
|
||||
switch (p[3]) {
|
||||
case DAC_VOLT:
|
||||
value = (p[4] << 8) | p[5]; // usercode
|
||||
|
||||
if (value < DAC_VOUT_GAIN_LARGE_BOUNDARY_USERCODE && value > DAC_VOUT_GAIN_LARGE_BOUNDARY1_USERCODE) {
|
||||
instru.VoutGainLv = VOUT_GAIN_15K;
|
||||
} else {
|
||||
instru.VoutGainLv = VOUT_GAIN_240K;
|
||||
}
|
||||
VoutGainControl(instru.VoutGainLv);
|
||||
|
||||
value = (value - 25000) * 4 * 10000; //[5nV]
|
||||
set_para(instru.eliteFxn, DAC_VOLT, value);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case MODE_DEV_TOOL: { // 0x3000FF
|
||||
mode_dev_tool(p);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
default: {
|
||||
/** **/
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static void ins_decode_vis(uint8_t *ins_buf)
|
||||
{
|
||||
uint8_t *p = ins_buf;
|
||||
uint8_t oper = p[1]; // this is don't care in RIS
|
||||
switch (oper) {
|
||||
// reset all variables ( Ins = 0xC0F0)
|
||||
case VIS_RST: {
|
||||
instru.eliteFxn = VIS_RST;
|
||||
reset();
|
||||
break;
|
||||
}
|
||||
|
||||
case VIS_ASK: {
|
||||
not_buf[0] = BLE_DAT_BUFF_SIZE - 1; //data len
|
||||
for (int i = 0; i < BLE_DAT_BUFF_SIZE; i++) {
|
||||
not_buf[i] = i;
|
||||
}
|
||||
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, BLE_DAT_BUFF_SIZE, not_buf);
|
||||
break;
|
||||
}
|
||||
|
||||
case VIS_STI: {
|
||||
for(int i = 0; i < 12; i++) {
|
||||
FlushNotify();
|
||||
}
|
||||
PeriodicEvent = true;
|
||||
InitPeriodicEvent = true; // need to create a WorkModeData?
|
||||
mode_init = true;
|
||||
InitGPT();
|
||||
break;
|
||||
}
|
||||
|
||||
case VIS_FUH: {
|
||||
led_color_set(LED_NB_MAX, LED_BR_LV1, LED_CLR_RED);
|
||||
break;
|
||||
}
|
||||
|
||||
case VIS_INT: {
|
||||
Eliteinterrupt();
|
||||
for (int i = 0; i < 12; i++) {
|
||||
FlushNotify();
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case VIS_DEVICE_SHINY: {
|
||||
led_color_set(LED_NB_MAX, LED_BR_LV1, LED_CLR_MAGENTA);
|
||||
break;
|
||||
}
|
||||
|
||||
case VIS_SHINY_DIS: {
|
||||
if (PeriodicEvent) {
|
||||
WORKLED();
|
||||
} else if (!PeriodicEvent) {
|
||||
checkFlafLED();
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case VIS_CC_ZERO: {
|
||||
instru.eliteFxn = CURVE_OCP;
|
||||
instru.notifyRate = 500;
|
||||
|
||||
if (instru.notifyRate > 1000) {
|
||||
// slow notify rate, < 10sps, auto gain changer only use ADC gain level = 1.2.3.4
|
||||
instru.gain_switch_on = 0b11110000;
|
||||
|
||||
} else {
|
||||
// fast notify rate, >= 10sps, auto gain changer only use ADC gain level = 1.2.3
|
||||
instru.gain_switch_on = 0b01110000;
|
||||
}
|
||||
|
||||
ModeLED(PRE_WORK);
|
||||
break;
|
||||
}
|
||||
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void ins_decode_cis(uint8_t *ins_buf)
|
||||
{
|
||||
uint8_t *p = ins_buf;
|
||||
uint8_t oper = p[1]; // this is don't care in RIS
|
||||
|
||||
switch (oper) {
|
||||
case CIS_VERSION: {
|
||||
initCISBuf();
|
||||
cis_buf[0] = 6; //data len
|
||||
cis_buf[1] = CIS_VERSION;
|
||||
cis_buf[2] = VERSION_DATE_YEAR;
|
||||
cis_buf[3] = VERSION_DATE_MONTH;
|
||||
cis_buf[4] = VERSION_DATE_DAY;
|
||||
cis_buf[5] = VERSION_DATE_HOUR;
|
||||
cis_buf[6] = VERSION_DATE_MINUTE;
|
||||
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, BLE_CIS_BUFF_SIZE, cis_buf);
|
||||
break;
|
||||
}
|
||||
|
||||
case CIS_VOLT: {
|
||||
// uint32_t bat = headstage_battery_volt();
|
||||
// initCISBuf();
|
||||
// cis_buf[0] = 5; //data len
|
||||
// cis_buf[1] = CIS_VOLT;
|
||||
// memcpy(&cis_buf[2], (uint8_t *)&bat, sizeof(bat));
|
||||
// SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, BLE_CIS_BUFF_SIZE, cis_buf);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
|
||||
case CIS_TEMPERATURE: { //0x7080
|
||||
int32_t t = headstage_temperature();
|
||||
initCISBuf();
|
||||
cis_buf[0] = 5; //data len
|
||||
cis_buf[1] = CIS_TEMPERATURE;
|
||||
memcpy(&cis_buf[2], (uint8_t *)&t, sizeof(t));
|
||||
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, BLE_CIS_BUFF_SIZE, cis_buf);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,313 +0,0 @@
|
||||
#include "HAL/cc2650_driver/i2c_ctrl.h"
|
||||
#include "HAL/MAX5136x2.h"
|
||||
/*
|
||||
* MODE_DEV_TOOL 0xFF
|
||||
* DEV_TOOL_VERSION [34 LL FF 01]
|
||||
*
|
||||
* DEV_TOOL_BAT [34 LL FF 02]
|
||||
*
|
||||
* DEV_TOOL_TEMP [34 LL FF 03]
|
||||
*
|
||||
* DEV_TOOL_LED [34 LL FF 04]
|
||||
* DEV_LED_LIMIT_COLOR [00 NN]
|
||||
* DEV_LED_DARK_COLOR [01 RR GG BB]
|
||||
* DEV_LED_LIGHT_COLOR [02 RR GG BB]
|
||||
* DEV_LED_RAINBOW [03]
|
||||
*
|
||||
* DEV_TOOL_SPI [34 LL FF 20 pp RR WW ss ss ss ...]
|
||||
* DT_CHIP_ADC pp = [00]
|
||||
* DT_CHIP_DAC pp = [01]
|
||||
* DT_CHIP_MEM pp = [02]
|
||||
* DT_CHIP_SWITCH pp = [03]
|
||||
*
|
||||
* DEV_TOOL_I2C [34 LL FF 28 qq RR WW ss ss ss ...]
|
||||
*
|
||||
* DEV_TOOL_GPIO_EDC20_ADC_CH [34 LL FF 31 cc]
|
||||
* cc = 07 => all open
|
||||
* cc = 04 => open A2
|
||||
* cc = 02 => open A1
|
||||
* cc = 01 => open A0
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
enum dev_tool_para_e {
|
||||
DEV_TOOL_VERSION = 0x01,
|
||||
DEV_TOOL_BAT = 0x02,
|
||||
DEV_TOOL_TEMP = 0x03,
|
||||
DEV_TOOL_LED = 0x04,
|
||||
DEV_TOOL_SPI = 0x20,
|
||||
DEV_TOOL_I2C = 0x28,
|
||||
DEV_TOOL_GPIO_EDC20_ADC_CH = 0x31,
|
||||
DEV_TOOL_OUT0_WRITE_THROUGH = 0x50,
|
||||
DEV_TOOL_SWITCH_SELECT = 0x60,
|
||||
};
|
||||
|
||||
enum dev_tool_chip_e {
|
||||
DT_CHIP_ADC = 0,
|
||||
DT_CHIP_DAC,
|
||||
DT_CHIP_MEM,
|
||||
DT_CHIP_SWITCH,
|
||||
DT_OPEN_SPI1 = 0x11,
|
||||
|
||||
DT_CHIP_MAX,
|
||||
};
|
||||
|
||||
enum dev_led_item_e {
|
||||
DEV_LED_LIMIT_COLOR = 0,
|
||||
DEV_LED_DARK_COLOR,
|
||||
DEV_LED_LIGHT_COLOR,
|
||||
DEV_LED_RAINBOW,
|
||||
|
||||
DEV_LED_MAX,
|
||||
};
|
||||
|
||||
static void dev_tool_version()
|
||||
{
|
||||
initCISBuf();
|
||||
cis_buf[0] = 6; //data len
|
||||
cis_buf[1] = DEV_TOOL_VERSION;
|
||||
cis_buf[2] = VERSION_DATE_YEAR;
|
||||
cis_buf[3] = VERSION_DATE_MONTH;
|
||||
cis_buf[4] = VERSION_DATE_DAY;
|
||||
cis_buf[5] = VERSION_DATE_HOUR;
|
||||
cis_buf[6] = VERSION_DATE_MINUTE;
|
||||
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, BLE_CIS_BUFF_SIZE, cis_buf);
|
||||
}
|
||||
|
||||
static void dev_tool_battery()
|
||||
{
|
||||
uint32_t bat;
|
||||
bat = headstage_battery_volt();
|
||||
|
||||
initCISBuf();
|
||||
cis_buf[0] = 5; //data len
|
||||
cis_buf[1] = DEV_TOOL_BAT;
|
||||
memcpy(&cis_buf[2], (uint8_t *)&bat, sizeof(bat));
|
||||
|
||||
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, BLE_CIS_BUFF_SIZE, cis_buf);
|
||||
}
|
||||
|
||||
static void dev_tool_temp()
|
||||
{
|
||||
int32_t t;
|
||||
|
||||
t = headstage_temperature();
|
||||
|
||||
initCISBuf();
|
||||
cis_buf[0] = 5; //data len
|
||||
cis_buf[1] = DEV_TOOL_TEMP;
|
||||
memcpy(&cis_buf[2], (uint8_t *)&t, sizeof(t));
|
||||
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, BLE_CIS_BUFF_SIZE, cis_buf);
|
||||
}
|
||||
|
||||
static int dev_tool_led(uint8_t *ins_buf)
|
||||
{
|
||||
uint8_t *p = ins_buf;
|
||||
struct led_color_t led_c;
|
||||
uint8_t led_item = p[4];
|
||||
uint8_t c_num = p[5];
|
||||
|
||||
led_c.r = p[5];
|
||||
led_c.g = p[6];
|
||||
led_c.b = p[7];
|
||||
|
||||
if (led_item >= DEV_LED_MAX)
|
||||
return -1;
|
||||
|
||||
if (led_item == DEV_LED_RAINBOW)
|
||||
return led_rainbow(LED_BR_LV1);
|
||||
|
||||
if (led_item == DEV_LED_LIMIT_COLOR)
|
||||
return led_color_set(LED_NB_MAX, LED_BR_LV1, (enum led_color_e)c_num);
|
||||
|
||||
if (led_item == DEV_LED_DARK_COLOR)
|
||||
return led_color_code_set(LED_NB_MAX, LED_BR_LV1, &led_c);
|
||||
|
||||
if (led_item == DEV_LED_LIGHT_COLOR)
|
||||
return led_color_code_set(LED_NB_MAX, LED_BR_LV8, &led_c);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void dev_tool_spi(uint8_t *ins_buf)
|
||||
{
|
||||
uint8_t *p = ins_buf;
|
||||
uint8_t chip_sel = p[4];
|
||||
|
||||
//ADC、DAC、MEM、SWITCH
|
||||
uint8_t rxlen = p[5];
|
||||
uint8_t txlen = p[6];
|
||||
uint8_t tx[250] = {0};
|
||||
uint8_t rx[250] = {0};
|
||||
|
||||
//set spi config
|
||||
uint8_t pol = p[5] >> 4;
|
||||
uint8_t pha = p[5] & 0X0F;
|
||||
|
||||
if (chip_sel >= DT_CHIP_MAX)
|
||||
return;
|
||||
|
||||
switch (chip_sel) {
|
||||
case DT_CHIP_ADC:
|
||||
pin_set(E_PIN_ADCCS, 0);
|
||||
memcpy(tx, &p[7], txlen);
|
||||
spi1_write(rx, tx, txlen);
|
||||
pin_set(E_PIN_ADCCS, 1);
|
||||
break;
|
||||
|
||||
case DT_CHIP_DAC:
|
||||
pin_set(E_PIN_DACCS, 0);
|
||||
memcpy(tx, &p[7], txlen);
|
||||
spi1_write(rx, tx, txlen);
|
||||
pin_set(E_PIN_DACCS, 1);
|
||||
break;
|
||||
|
||||
case DT_CHIP_MEM:
|
||||
pin_set(E_PIN_MEMCS, 0);
|
||||
memcpy(tx, &p[7], txlen);
|
||||
spi1_write(rx, tx, txlen);
|
||||
pin_set(E_PIN_MEMCS, 1);
|
||||
break;
|
||||
|
||||
case DT_CHIP_SWITCH:
|
||||
pin_set(E_PIN_SWCSBB, 0);
|
||||
memcpy(tx, &p[7], txlen);
|
||||
spi1_write(rx, tx, txlen);
|
||||
pin_set(E_PIN_SWCSBB, 1);
|
||||
break;
|
||||
|
||||
case DT_OPEN_SPI1:
|
||||
spi1_close();
|
||||
spi1_open(SPI_CLK_4M, pol, pha);
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
initCISBuf();
|
||||
cis_buf[0] = rxlen + 1; //data len
|
||||
cis_buf[1] = DEV_TOOL_SPI;
|
||||
memcpy(&cis_buf[2], rx, rxlen);
|
||||
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, BLE_CIS_BUFF_SIZE, cis_buf);
|
||||
|
||||
}
|
||||
|
||||
static void dev_tool_i2c(uint8_t *ins_buf)
|
||||
{
|
||||
uint8_t *p = ins_buf;
|
||||
struct i2c_para_t i2c_send;
|
||||
struct i2c_para_t *send = &i2c_send;
|
||||
|
||||
send->i2c_addr = p[4];
|
||||
send->i2c_rxlen = p[5];
|
||||
send->i2c_txlen = p[6];
|
||||
memcpy(send->i2c_tx, &p[7], send->i2c_txlen);
|
||||
|
||||
i2c0_write(send);
|
||||
|
||||
initCISBuf();
|
||||
cis_buf[0] = send->i2c_rxlen + 2; //data len
|
||||
cis_buf[1] = DEV_TOOL_I2C;
|
||||
memcpy(&cis_buf[2], send->i2c_rx, send->i2c_rxlen);
|
||||
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, BLE_CIS_BUFF_SIZE, cis_buf);
|
||||
}
|
||||
|
||||
static void dev_tool_gpio_edc20_adc_ch(uint8_t *ins_buf)
|
||||
{
|
||||
uint8_t *p = ins_buf;
|
||||
uint8_t adc_selector = p[4];
|
||||
|
||||
adc_sel_set(adc_selector);
|
||||
|
||||
}
|
||||
|
||||
static void dev_tool_dac_write(uint8_t *ins_buf)
|
||||
{
|
||||
|
||||
|
||||
uint8_t *p = ins_buf;
|
||||
dac_series_control_g[DAC_NB_0].dac0_enable = (p[4] & 0xf0) >> 4;
|
||||
dac_series_control_g[DAC_NB_0].dac1_enable = (p[4] & 0x0f);
|
||||
dac_series_control_g[DAC_NB_0].volts = (uint16_t) p[5] << 8 | (uint16_t) p[6];
|
||||
|
||||
dac_series_control_g[DAC_NB_1].dac0_enable = (p[7] & 0xf0) >> 4;
|
||||
dac_series_control_g[DAC_NB_1].dac1_enable = (p[7] & 0x0f);
|
||||
dac_series_control_g[DAC_NB_1].volts = (uint16_t) p[8] << 8 | (uint16_t) p[9];
|
||||
|
||||
dac_enable_all_output(dac_series_control_g);
|
||||
}
|
||||
|
||||
|
||||
static void dev_tool_dac_write_single(uint8_t *ins_buf) {
|
||||
uint8_t *p = ins_buf;
|
||||
uint8_t dac0_enable = (p[4] & 0xf0) >> 4;
|
||||
uint8_t dac1_enable = (p[4] & 0x0f);
|
||||
uint16_t volts = (uint16_t) p[5] << 8 | (uint16_t) p[6];
|
||||
enum MAX5136_num_e dac_num = (enum MAX5136_num_e) p[7];
|
||||
|
||||
dac_enable_single_output(dac0_enable, dac1_enable, volts, dac_num);
|
||||
}
|
||||
|
||||
static void dev_tool_switch_select(uint8_t *ins_buf)
|
||||
{
|
||||
uint8_t *p = ins_buf;
|
||||
|
||||
uint8_t switch_module_number = p[4];
|
||||
uint8_t enable_type = p[5];
|
||||
|
||||
switch_ctrl(switch_module_number, enable_type);
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void mode_dev_tool(uint8_t *ins_buf)
|
||||
{
|
||||
uint8_t *p = ins_buf;
|
||||
uint8_t dev_item = p[3];
|
||||
|
||||
switch (dev_item) {
|
||||
case DEV_TOOL_VERSION:
|
||||
dev_tool_version();
|
||||
break;
|
||||
|
||||
case DEV_TOOL_BAT:
|
||||
dev_tool_battery();
|
||||
break;
|
||||
|
||||
case DEV_TOOL_TEMP:
|
||||
dev_tool_temp();
|
||||
break;
|
||||
|
||||
case DEV_TOOL_LED:
|
||||
dev_tool_led(p);
|
||||
break;
|
||||
|
||||
case DEV_TOOL_SPI:
|
||||
dev_tool_spi(p);
|
||||
break;
|
||||
|
||||
case DEV_TOOL_I2C:
|
||||
dev_tool_i2c(p);
|
||||
break;
|
||||
|
||||
case DEV_TOOL_GPIO_EDC20_ADC_CH:
|
||||
dev_tool_gpio_edc20_adc_ch(p);
|
||||
break;
|
||||
|
||||
case DEV_TOOL_OUT0_WRITE_THROUGH:
|
||||
dev_tool_dac_write(p);
|
||||
break;
|
||||
|
||||
case DEV_TOOL_SWITCH_SELECT:
|
||||
dev_tool_switch_select(p);
|
||||
break;
|
||||
|
||||
|
||||
default:
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -50,15 +50,9 @@
|
||||
|
||||
#include <xdc/runtime/Error.h>
|
||||
|
||||
|
||||
#include <ti/drivers/Power.h>
|
||||
#include <ti/drivers/power/PowerCC26XX.h>
|
||||
#include <ti/sysbios/BIOS.h>
|
||||
#include <ti/drivers/SPI.h>
|
||||
#include <ti/drivers/spi/SPICC26XXDMA.h>
|
||||
#include <ti/drivers/dma/UDMACC26XX.h>
|
||||
#include <ti/drivers/I2C.h>
|
||||
#include <ti/drivers/i2c/I2CCC26XX.h>
|
||||
|
||||
#include "icall.h"
|
||||
#include "hal_assert.h"
|
||||
|
||||
@@ -637,9 +637,13 @@ static bStatus_t simpleProfile_ReadAttrCB(uint16_t connHandle,
|
||||
case SIMPLEPROFILE_CHAR1_UUID:
|
||||
*pLen = SIMPLEPROFILE_CHAR1_LEN;
|
||||
VOID memcpy( pValue, pAttr->pValue, SIMPLEPROFILE_CHAR1_LEN );
|
||||
break;
|
||||
|
||||
case SIMPLEPROFILE_CHAR2_UUID:
|
||||
*pLen = SIMPLEPROFILE_CHAR2_LEN;
|
||||
*pLen = SIMPLEPROFILE_CHAR2_LEN;
|
||||
VOID memcpy( pValue, pAttr->pValue, SIMPLEPROFILE_CHAR2_LEN );
|
||||
break;
|
||||
|
||||
case SIMPLEPROFILE_CHAR4_UUID:
|
||||
*pLen = SIMPLEPROFILE_CHAR4_LEN;
|
||||
VOID memcpy( pValue, pAttr->pValue, SIMPLEPROFILE_CHAR4_LEN );
|
||||
@@ -695,9 +699,8 @@ static bStatus_t simpleProfile_WriteAttrCB(uint16_t connHandle,
|
||||
uint16 uuid = BUILD_UINT16( pAttr->type.uuid[0], pAttr->type.uuid[1]);
|
||||
switch ( uuid )
|
||||
{
|
||||
case SIMPLEPROFILE_CHAR1_UUID:
|
||||
// case SIMPLEPROFILE_CHAR1_UUID:
|
||||
case SIMPLEPROFILE_CHAR3_UUID:
|
||||
|
||||
//Validate the value
|
||||
// Make sure it's not a blob oper
|
||||
if ( offset == 0 )
|
||||
@@ -715,25 +718,52 @@ static bStatus_t simpleProfile_WriteAttrCB(uint16_t connHandle,
|
||||
//Write the value
|
||||
if ( status == SUCCESS )
|
||||
{
|
||||
uint8 *pCurValue = (uint8 *)pAttr->pValue;
|
||||
*pCurValue = pValue[0];
|
||||
|
||||
// Copy pValue into the variable we point to from the attribute table.
|
||||
memcpy(pAttr->pValue + offset, pValue, len);
|
||||
memset(pAttr->pValue + len, 0, SIMPLEPROFILE_CHAR3_LEN - len);
|
||||
memcpy(pAttr->pValue+offset, pValue, len);
|
||||
memset(pAttr->pValue+len, 0, SIMPLEPROFILE_CHAR3_LEN-len);
|
||||
|
||||
if( pAttr->pValue == simpleProfileChar1 )
|
||||
{
|
||||
notifyApp = SIMPLEPROFILE_CHAR1;
|
||||
}
|
||||
else
|
||||
if( pAttr->pValue == simpleProfileChar3 )
|
||||
{
|
||||
notifyApp = SIMPLEPROFILE_CHAR3;
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
// case SIMPLEPROFILE_CHAR1_UUID:
|
||||
// case SIMPLEPROFILE_CHAR3_UUID:
|
||||
|
||||
// //Validate the value
|
||||
// // Make sure it's not a blob oper
|
||||
// if ( offset == 0 )
|
||||
// {
|
||||
// if ( len != 1 )
|
||||
// {
|
||||
// status = ATT_ERR_INVALID_VALUE_SIZE;
|
||||
// }
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// status = ATT_ERR_ATTR_NOT_LONG;
|
||||
// }
|
||||
|
||||
// //Write the value
|
||||
// if ( status == SUCCESS )
|
||||
// {
|
||||
// uint8 *pCurValue = (uint8 *)pAttr->pValue;
|
||||
// *pCurValue = pValue[0];
|
||||
|
||||
// if( pAttr->pValue == &simpleProfileChar1 )
|
||||
// {
|
||||
// notifyApp = SIMPLEPROFILE_CHAR1;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// notifyApp = SIMPLEPROFILE_CHAR3;
|
||||
// }
|
||||
// }
|
||||
|
||||
// break;
|
||||
|
||||
case GATT_CLIENT_CHAR_CFG_UUID:
|
||||
status = GATTServApp_ProcessCCCWriteReq( connHandle, pAttr, pValue, len,
|
||||
offset, GATT_CLIENT_CFG_NOTIFY );
|
||||
|
||||
@@ -56,7 +56,7 @@ extern "C"
|
||||
/*********************************************************************
|
||||
* INCLUDES
|
||||
*/
|
||||
#include "application_config/application_config.h"
|
||||
|
||||
/*********************************************************************
|
||||
* CONSTANTS
|
||||
*/
|
||||
@@ -81,24 +81,13 @@ extern "C"
|
||||
// Simple Keys Profile Services bit fields
|
||||
#define SIMPLEPROFILE_SERVICE 0x00000001
|
||||
|
||||
#ifndef CUSTOM_GATT_LENGTH
|
||||
// Length of Characteristic 5 in bytes
|
||||
#define SIMPLEPROFILE_CHAR5_LEN 5
|
||||
#define SIMPLEPROFILE_CHAR4_LEN 20
|
||||
#define SIMPLEPROFILE_CHAR4_LEN 40
|
||||
#define SIMPLEPROFILE_CHAR3_LEN 20
|
||||
#define SIMPLEPROFILE_CHAR2_LEN 20
|
||||
#define SIMPLEPROFILE_CHAR1_LEN 20
|
||||
#else
|
||||
/*user insert*/
|
||||
#define SIMPLEPROFILE_CHAR5_LEN 5
|
||||
#define SIMPLEPROFILE_CHAR4_LEN BLE_DAT_BUFF_SIZE
|
||||
#define SIMPLEPROFILE_CHAR3_LEN BLE_INS_BUFF_SIZE
|
||||
#define SIMPLEPROFILE_CHAR2_LEN BLE_CIS_BUFF_SIZE
|
||||
#define SIMPLEPROFILE_CHAR1_LEN 20
|
||||
#define BLE_CIS_BUFF_CHAR SIMPLEPROFILE_CHAR2
|
||||
#define BLE_INS_BUFF_CHAR SIMPLEPROFILE_CHAR3
|
||||
#define BLE_DAT_BUFF_CHAR SIMPLEPROFILE_CHAR4
|
||||
#endif
|
||||
|
||||
/*********************************************************************
|
||||
* TYPEDEFS
|
||||
*/
|
||||
|
||||