Compare commits
142 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 49b11af639 | |||
| 7f703de601 | |||
| d0988e4027 | |||
| 3f416f17b3 | |||
| d706fe9c3e | |||
| c52078cc30 | |||
| 9472ff4ce2 | |||
| 52643ae5d7 | |||
| 09d51b5fd6 | |||
| fe13bf4f42 | |||
| 0607d6cf9b | |||
| 2361e857e9 | |||
| 49d13b8d34 | |||
| 1462879b29 | |||
| 9484705b3b | |||
| 35502b18f0 | |||
| 1dbffad946 | |||
| 65bb984692 | |||
| 890df7ce16 | |||
| 56dca39a16 | |||
| 8162d4eca6 | |||
| 2067de1fb6 | |||
| 2bcccf6036 | |||
| 31c8797a82 | |||
| b359ebf5f9 | |||
| 55c4df4dcb | |||
| 2fbd57cfb4 | |||
| 75e21615d0 | |||
| 97495ceb25 | |||
| 258b8a1c02 | |||
| 46ea9c7afd | |||
| e188cd23c4 | |||
| da720eb9f4 | |||
| d342ae3e9c | |||
| a9d24ad477 | |||
| 7759c9eae9 | |||
| 9e42593882 | |||
| af03bc03e2 | |||
| d096eabf47 | |||
| 441bd80595 | |||
| 3557c3d288 | |||
| 16ac2ab82d | |||
| 6756a057bc | |||
| 00c61096b7 | |||
| 119285f7c8 | |||
| fce1a943e1 | |||
| 30bd896d4c | |||
| 5b2ccf8e7c | |||
| ea24ba5406 | |||
| a23083c080 | |||
| 735ffa2bef | |||
| 5ad2759a81 | |||
| 31c990bc18 | |||
| 9c839a181f | |||
| a10517bf38 | |||
| ac7aaad5a2 | |||
| bc21e3cb27 | |||
| 9baa4e8ae0 | |||
| 00e233cc9e | |||
| 13b4e2253c | |||
| 9c29ad0a86 | |||
| 6b421d73e9 | |||
| 34107872ec | |||
| f6719c3182 | |||
| 79188d76b9 | |||
| 3e5c9b9b73 | |||
| f1fa366b8f | |||
| 16814ad816 | |||
| 92ae63b7f9 | |||
| 1f3e7a5efe | |||
| c573135e98 | |||
| 5d4c5b5a86 | |||
| caf6985e66 | |||
| a7a1f7f2b5 | |||
| 45182935b7 | |||
| 6958c410a1 | |||
| a337434903 | |||
| 14c897c26e | |||
| 02a6018cac | |||
| 544b571f85 | |||
| 939de9098a | |||
| 7441d9a5c8 | |||
| a680f59277 | |||
| b595215326 | |||
| 901108ea90 | |||
| 16dc76833a | |||
| e6993f5a4a | |||
| a2b5a5728b | |||
| 4d76e4585e | |||
| 43e72567c0 | |||
| 311f0d1238 | |||
| 7177e8549b | |||
| 7106f59122 | |||
| 2c203b73a1 | |||
| ba7552e091 | |||
| 4b65c8666e | |||
| 5dc35425d5 | |||
| 790db4bcf4 | |||
| d9cc6f2ba6 | |||
| 5e04fcb7e2 | |||
| dc5cabf2ae | |||
| 7cf60e2717 | |||
| f1ab4be88a | |||
| 3509b6df00 | |||
| 26b37b759f | |||
| 6321fdca51 | |||
| c496ccb791 | |||
| c8aeabdfeb | |||
| 9bfc251029 | |||
| 0273a9571b | |||
| 5318a89132 | |||
| a4f653951e | |||
| 925447817f | |||
| b64a3d031f | |||
| 6fc7b2591f | |||
| 00cc58e720 | |||
| fcc1477acd | |||
| 545fc8323c | |||
| 4c654982d2 | |||
| d7a4e02349 | |||
| ee1d052c3a | |||
| 7acafa81b8 | |||
| e97d556dd9 | |||
| c227d21546 | |||
| f9e33d0ede | |||
| a9fd1028d1 | |||
| f6a20eaea5 | |||
| f904bbd522 | |||
| 6f3a1b57ae | |||
| b795b7eb6b | |||
| a1adf82f2b | |||
| 061064c27a | |||
| 2d1556686c | |||
| 0d7f334499 | |||
| b849231be3 | |||
| 060dde64a8 | |||
| 6be73528d4 | |||
| 7b4436920f | |||
| b34e947cc8 | |||
| 8c4737e494 | |||
| 6f36e781b7 | |||
| 8403c16fa0 |
@@ -0,0 +1,55 @@
|
||||
#Generated from Visual Studio settings
|
||||
---
|
||||
BasedOnStyle: webkit
|
||||
BraceWrapping:
|
||||
BeforeCatch: true
|
||||
BeforeElse: true
|
||||
AfterClass: true
|
||||
AfterFunction: true
|
||||
AfterControlStatement: true
|
||||
AfterEnum: true
|
||||
AfterNamespace: true
|
||||
AfterObjCDeclaration: true
|
||||
AfterStruct: true
|
||||
AfterUnion: true
|
||||
AfterExternBlock: true
|
||||
ColumnLimit: 0
|
||||
BreakBeforeBraces: Custom
|
||||
NamespaceIndentation: All
|
||||
TabWidth: 4
|
||||
IndentCaseLabels: true
|
||||
AlignAfterOpenBracket: Align
|
||||
PointerAlignment: Right
|
||||
AlignOperands: true
|
||||
AllowAllParametersOfDeclarationOnNextLine: false
|
||||
AllowShortLoopsOnASingleLine: true
|
||||
AllowShortIfStatementsOnASingleLine: true
|
||||
BinPackArguments: false
|
||||
BinPackParameters: false
|
||||
BreakBeforeBinaryOperators: None
|
||||
BreakBeforeTernaryOperators: false
|
||||
BreakAfterJavaFieldAnnotations: true
|
||||
AlignConsecutiveAssignments: true
|
||||
AlignTrailingComments: true
|
||||
BreakConstructorInitializers: AfterColon
|
||||
AlignConsecutiveMacros:
|
||||
Enabled: true
|
||||
AcrossEmptyLines: true
|
||||
AcrossComments: true
|
||||
AlignArrayOfStructures: Right
|
||||
AlignConsecutiveAssignments:
|
||||
Enabled: true
|
||||
AcrossEmptyLines: false
|
||||
AcrossComments: false
|
||||
AlignCompound: true
|
||||
PadOperators: true
|
||||
AlignConsecutiveBitFields:
|
||||
Enabled: true
|
||||
AcrossEmptyLines: false
|
||||
AcrossComments: false
|
||||
AlignCompound: true
|
||||
PadOperators: true
|
||||
AlignEscapedNewlines: Right
|
||||
BinPackArguments: false
|
||||
BinPackParameters: false
|
||||
...
|
||||
|
Before Width: | Height: | Size: 144 KiB |
|
Before Width: | Height: | Size: 128 KiB |
|
Before Width: | Height: | Size: 152 KiB |
|
Before Width: | Height: | Size: 173 KiB |
|
Before Width: | Height: | Size: 203 KiB |
|
Before Width: | Height: | Size: 149 KiB |
|
Before Width: | Height: | Size: 127 KiB |
|
Before Width: | Height: | Size: 112 KiB |
|
Before Width: | Height: | Size: 174 KiB |
|
Before Width: | Height: | Size: 208 KiB |
|
Before Width: | Height: | Size: 155 KiB |
|
Before Width: | Height: | Size: 133 KiB |
|
Before Width: | Height: | Size: 154 KiB |
|
Before Width: | Height: | Size: 171 KiB |
|
Before Width: | Height: | Size: 212 KiB |
|
Before Width: | Height: | Size: 152 KiB |
|
Before Width: | Height: | Size: 135 KiB |
|
Before Width: | Height: | Size: 107 KiB |
|
Before Width: | Height: | Size: 169 KiB |
|
Before Width: | Height: | Size: 203 KiB |
|
After Width: | Height: | Size: 48 KiB |
|
After Width: | Height: | Size: 166 KiB |
@@ -50,7 +50,7 @@ extern "C" {
|
||||
* ==========================================================================*/
|
||||
#include <ti/drivers/PIN.h>
|
||||
#include <driverlib/ioc.h>
|
||||
#include "app_config.h"
|
||||
#include "boards_config/elite_boards_select.h"
|
||||
|
||||
/** ============================================================================
|
||||
* Externs
|
||||
@@ -146,6 +146,12 @@ extern const PIN_Config BoardGpioInitTable[];
|
||||
#define Board_UART_TX Board_BP_UART_Rx /* RXD */
|
||||
#define Board_UART_RX Board_BP_UART_Tx /* TXD */
|
||||
|
||||
// /* SPI Board */
|
||||
// #define Board_SPI0_MISO Board_BP_SPI_MISO
|
||||
// #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
|
||||
|
||||
/* Power Management Board */
|
||||
#define Board_SRDY Board_BP_Pin_J2_19
|
||||
#define Board_MRDY Board_BP_Pin_J1_2
|
||||
@@ -160,28 +166,6 @@ extern const PIN_Config BoardGpioInitTable[];
|
||||
#define Board_PWMPIN6 PIN_UNASSIGNED
|
||||
#define Board_PWMPIN7 PIN_UNASSIGNED
|
||||
|
||||
/* SPI & I2C Board */
|
||||
#ifndef DEF_ELITE_MODEL
|
||||
#define Board_SPI0_MISO Board_BP_SPI_MISO
|
||||
#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
|
||||
#define Board_SPI0_CLK E_SPI0_CLK
|
||||
#define Board_SPI0_CS E_SPI0_CS
|
||||
|
||||
#define Board_SPI1_MISO E_SPI1_MISO
|
||||
#define Board_SPI1_MOSI E_SPI1_MOSI
|
||||
#define Board_SPI1_CLK E_SPI1_CLK
|
||||
#define Board_SPI1_CS E_SPI1_CS
|
||||
|
||||
#define Board_I2C0_SCL0 E_I2C0_SCL0
|
||||
#define Board_I2C0_SDA0 E_I2C0_SDA0
|
||||
#endif
|
||||
|
||||
/** ============================================================================
|
||||
* Instance identifiers
|
||||
* ==========================================================================*/
|
||||
|
||||
@@ -1,147 +0,0 @@
|
||||
#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,245 +0,0 @@
|
||||
#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
|
||||
|
||||
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};
|
||||
|
||||
void ADGS1412_daisy_chain_mode(void)
|
||||
{
|
||||
uint8_t cmd_daisy_chain[2] = {0x25, 0x00};
|
||||
|
||||
#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;
|
||||
}
|
||||
@@ -1,330 +0,0 @@
|
||||
/*
|
||||
* 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();
|
||||
}
|
||||
@@ -1,63 +0,0 @@
|
||||
#ifndef APA102_2020_256_8X4_H
|
||||
#define APA102_2020_256_8X4_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define LED_TANDEM_N 4
|
||||
|
||||
enum led_series_nb_e {
|
||||
LED_NB_1 = 0,
|
||||
LED_NB_2,
|
||||
LED_NB_3,
|
||||
LED_NB_4,
|
||||
|
||||
LED_NB_MAX = LED_TANDEM_N,
|
||||
};
|
||||
|
||||
enum led_bright_e {
|
||||
LED_BR_LV0 = 0x00,
|
||||
LED_BR_LV1 = 0x01,
|
||||
LED_BR_LV8 = 0x08,
|
||||
|
||||
LED_BR_MAX = 0x1F,
|
||||
};
|
||||
|
||||
enum led_color_e {
|
||||
LED_CLR_BLACK = 0,
|
||||
LED_CLR_WHITE,
|
||||
LED_CLR_RED,
|
||||
LED_CLR_ORANGE,
|
||||
LED_CLR_YELLOW,
|
||||
LED_CLR_GREEN,
|
||||
LED_CLR_CYAN,
|
||||
LED_CLR_BLUE,
|
||||
LED_CLR_PURPLE,
|
||||
LED_CLR_MAGENTA,
|
||||
LED_CLR_YELLOWGREEN,
|
||||
LED_CLR_EMERALD,
|
||||
|
||||
LED_CLR_MAX,
|
||||
};
|
||||
|
||||
struct led_color_t {
|
||||
uint8_t b;
|
||||
uint8_t g;
|
||||
uint8_t r;
|
||||
};
|
||||
|
||||
struct led_frame_t {
|
||||
uint8_t bright: 5,
|
||||
rsvd: 3;
|
||||
struct led_color_t color;
|
||||
};
|
||||
|
||||
int led_color_set(enum led_series_nb_e led_nb, enum led_bright_e bright, enum led_color_e color);
|
||||
int led_color_code_set(enum led_series_nb_e led_nb, enum led_bright_e bright, struct led_color_t *color);
|
||||
int led_rainbow(enum led_bright_e bright);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
@@ -1,204 +0,0 @@
|
||||
/*
|
||||
* APA-102-2020-256-8A-20190612: Series data structure
|
||||
* +-------------------+------------------------- ... -+-----------------+
|
||||
* | start_frame(4B) | led_frame(4B) *LED_TANDEM_N | end_frame(4B) |
|
||||
* +-------------------+------------------------- ... -+-----------------+
|
||||
* / \
|
||||
* / led_frame(4B) \
|
||||
* / \
|
||||
* 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
|
||||
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
* | 111 | bright | blue | green | red |
|
||||
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
*/
|
||||
|
||||
#include "HAL/APA102_2020_256_8x4.h"
|
||||
#include "HAL/cc2650_driver/spi_ctrl.h"
|
||||
|
||||
#define LED_FRME_FILL_RSVD(_f) (_f)->rsvd = 0x07 // 0x11100000 || bright
|
||||
#define LED_SERIES_D_START 0x00000000
|
||||
#define LED_SERIES_D_END 0xFFFFFFFF
|
||||
|
||||
struct led_series_data_t {
|
||||
uint32_t f_start;
|
||||
struct led_frame_t f_led[LED_TANDEM_N];
|
||||
uint32_t f_end;
|
||||
};
|
||||
|
||||
static struct led_series_data_t led_series_data_g = {0};
|
||||
|
||||
const struct led_color_t led_color_list_g[LED_CLR_MAX] = {
|
||||
// {blue, green, red}
|
||||
{0x00, 0x00, 0x00}, // LED_CLR_BLACK
|
||||
{0xFF, 0xFF, 0xCA}, // LED_CLR_WHITE
|
||||
{0x00, 0x00, 0xFF}, // LED_CLR_RED
|
||||
{0x09, 0x58, 0xFF}, // LED_CLR_ORANGE
|
||||
{0x00, 0xE1, 0xE1}, // LED_CLR_YELLOW
|
||||
{0x00, 0xFA, 0x00}, // LED_CLR_GREEN
|
||||
{0x40, 0x40, 0x00}, // LED_CLR_CYAN
|
||||
{0xAA, 0x00, 0x00}, // LED_CLR_BLUE
|
||||
{0x6F, 0x00, 0x3A}, // LED_CLR_PURPLE
|
||||
{0xFF, 0x00, 0xFF}, // LED_CLR_MAGENTA
|
||||
{0x00, 0xA6, 0x64}, // LED_CLR_YELLOWGREEN
|
||||
{0x78, 0xC8, 0x50}, // LED_CLR_EMERALD
|
||||
};
|
||||
|
||||
static int __led_single_set(struct led_series_data_t *led_s_d, struct led_frame_t *led_f, enum led_series_nb_e led_nb)
|
||||
{
|
||||
struct led_series_data_t *sd = led_s_d;
|
||||
struct led_frame_t *f = led_f;
|
||||
enum led_series_nb_e nb = led_nb;
|
||||
|
||||
memcpy(&sd->f_led[nb], f, sizeof(struct led_frame_t));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int __led_multiple_set(struct led_series_data_t *led_s_d, struct led_frame_t *led_f)
|
||||
{
|
||||
struct led_series_data_t *sd = led_s_d;
|
||||
struct led_frame_t *f = led_f;
|
||||
int i;
|
||||
|
||||
/*
|
||||
* use __led_single_set() to finish all led;
|
||||
*/
|
||||
for (i = LED_NB_1; i < LED_NB_MAX; i++) {
|
||||
__led_single_set(sd, f, (enum led_series_nb_e)i);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int __led_complete(struct led_series_data_t *led_s_d)
|
||||
{
|
||||
struct led_series_data_t *sd = led_s_d;
|
||||
struct led_frame_t *f = sd->f_led;
|
||||
int i;
|
||||
|
||||
for (i = LED_NB_1; i < LED_NB_MAX; i++) {
|
||||
LED_FRME_FILL_RSVD(f);
|
||||
f++;
|
||||
}
|
||||
|
||||
sd->f_start = LED_SERIES_D_START;
|
||||
sd->f_end = LED_SERIES_D_END;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int __led_color_set(enum led_series_nb_e led_nb, struct led_frame_t *led_f)
|
||||
{
|
||||
enum led_series_nb_e nb = led_nb;
|
||||
struct led_frame_t *f = led_f;
|
||||
struct led_series_data_t *sd = &led_series_data_g;
|
||||
|
||||
if (f == NULL)
|
||||
return -1;
|
||||
|
||||
/*
|
||||
* nb - < LED_NB_MAX: fill one led_frame
|
||||
* == LED_NB_MAX: fill multiple led_frame
|
||||
*
|
||||
* complete: then, fill (start_frame, end_frame and the rsvd of every led_frame)
|
||||
*
|
||||
* finally, write cmd to hw by spi
|
||||
*/
|
||||
if (nb < LED_NB_MAX) {
|
||||
__led_single_set(sd, f, nb);
|
||||
} else if (nb == LED_NB_MAX) {
|
||||
__led_multiple_set(sd, f);
|
||||
} else {
|
||||
return -2;
|
||||
}
|
||||
|
||||
__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;
|
||||
}
|
||||
|
||||
int led_color_set(enum led_series_nb_e led_nb, enum led_bright_e bright, enum led_color_e color)
|
||||
{
|
||||
enum led_series_nb_e nb = led_nb;
|
||||
enum led_bright_e b = bright;
|
||||
enum led_color_e c = color;
|
||||
struct led_frame_t led_f;
|
||||
|
||||
if (nb > LED_NB_MAX)
|
||||
return -1;
|
||||
|
||||
if (c >= LED_CLR_MAX)
|
||||
return -2;
|
||||
|
||||
if (b > LED_BR_MAX)
|
||||
return -3;
|
||||
|
||||
led_f.bright = b;
|
||||
led_f.color = led_color_list_g[c];
|
||||
__led_color_set(nb, &led_f);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int led_color_code_set(enum led_series_nb_e led_nb, enum led_bright_e bright, struct led_color_t *color)
|
||||
{
|
||||
enum led_series_nb_e nb = led_nb;
|
||||
enum led_bright_e b = bright;
|
||||
struct led_color_t *c = color;
|
||||
struct led_frame_t led_f;
|
||||
|
||||
// valid the input values
|
||||
if (nb > LED_NB_MAX)
|
||||
return -1;
|
||||
|
||||
if (b > LED_BR_MAX)
|
||||
return -2;
|
||||
|
||||
led_f.bright = b;
|
||||
memcpy(&led_f.color, c, sizeof(struct led_color_t));
|
||||
|
||||
__led_color_set(nb, &led_f);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int led_rainbow(enum led_bright_e bright)
|
||||
{
|
||||
enum led_bright_e b = bright;
|
||||
int i;
|
||||
|
||||
if (b > LED_BR_MAX)
|
||||
return -1;
|
||||
|
||||
for(i=0; i<LED_NB_MAX; i++) {
|
||||
led_color_set((enum led_series_nb_e)i, b, (enum led_color_e)i);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* example -
|
||||
* customize color:
|
||||
* struct led_color_t led_c;
|
||||
* uint8_t bri;
|
||||
* // { ins, ins, num, r, g, b, bri};
|
||||
* uint8_t ins[20] = {0x30, 0x00, LED_NB_4, 0xFF, 0x00, 0x44, 0x3};
|
||||
* led_c.r = ins[3];
|
||||
* led_c.g = ins[4];
|
||||
* led_c.b = ins[5];
|
||||
* bri = ins[6];
|
||||
* led_color_code_set(LED_NB_4, bri, &led_c);
|
||||
*
|
||||
* single led:
|
||||
* led_color_set(LED_NB_1, LED_BR_LV1, LED_CLR_WHITE);
|
||||
*
|
||||
* multiple led:
|
||||
* led_color_set(LED_NB_MAX, LED_BR_LV1, LED_CLR_BLUE);
|
||||
*
|
||||
* rainbow led:
|
||||
* led_rainbow(LED_BR_LV1);
|
||||
*/
|
||||
@@ -1,137 +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_code |
|
||||
* +-+-+-+-+--+--+--+--+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
*/
|
||||
#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
|
||||
|
||||
// Elite Conponent id:
|
||||
#define COMPONENT_DAC_U38 0x00 // spi_sequence:first
|
||||
#define COMPONENT_DAC_U37 0x01 // spi_sequence:second
|
||||
#define COMPONENT_DAC_MAX 0x02
|
||||
|
||||
// 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).
|
||||
|
||||
// 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
|
||||
|
||||
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};
|
||||
|
||||
/**
|
||||
@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 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);
|
||||
|
||||
#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;
|
||||
}
|
||||
}
|
||||
@@ -1,534 +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|
|
||||
* +-+-+-+-+--+--+--+---+ (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
|
||||
*
|
||||
*/
|
||||
|
||||
#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
|
||||
|
||||
#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)*/
|
||||
MCP23008_REG_IPOL, /*IPOL – INPUT POLARITY PORT REGISTER (ADDR 0x01)*/
|
||||
MCP23008_REG_GPINTEN, /*GPINTEN – INTERRUPT-ON-CHANGE PINS (ADDR 0x02)*/
|
||||
MCP23008_REG_DEFVAL, /*DEFVAL – DEFAULT VALUE REGISTER (ADDR 0x03)*/
|
||||
MCP23008_REG_INTCON, /*INTCON – INTERRUPT-ON-CHANGE CONTROL REGISTER (ADDR 0x04)*/
|
||||
MCP23008_REG_IOCON, /*IOCON – I/O EXPANDER CONFIGURATION REGISTER (ADDR 0x05)*/
|
||||
MCP23008_REG_GPPU, /*GPPU – GPIO PULL-UP RESISTOR REGISTER (ADDR 0x06)*/
|
||||
MCP23008_REG_INTF, /*INTF – INTERRUPT FLAG REGISTER (ADDR 0x07)*/
|
||||
MCP23008_REG_INTCAP, /*INTCAP – INTERRUPT CAPTURED VALUE FOR PORT REGISTER (ADDR 0x08)*/
|
||||
MCP23008_REG_GPIO, /*GPIO – GENERAL PURPOSE I/O PORT REGISTER (ADDR 0x09)*/
|
||||
MCP23008_REG_OLAT, /*OLAT – OUTPUT LATCH REGISTER 0 (ADDR 0x0A)*/
|
||||
|
||||
MCP23008_REG_MAX,
|
||||
};
|
||||
|
||||
struct mcp23008_reg_name_t {
|
||||
uint8_t iodir;
|
||||
uint8_t gpio;
|
||||
};
|
||||
|
||||
struct mcp23008_reg_name_t mcp23008_pa = {0};
|
||||
struct mcp23008_reg_name_t mcp23008_pb = {0};
|
||||
|
||||
/*
|
||||
* 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;
|
||||
}
|
||||
|
||||
#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);
|
||||
}
|
||||
@@ -1,138 +0,0 @@
|
||||
#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
|
||||
}
|
||||
@@ -1,173 +0,0 @@
|
||||
#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,28 +0,0 @@
|
||||
#ifndef SPI_CTRL_H
|
||||
#define SPI_CTRL_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define POL0 0
|
||||
#define POL1 1
|
||||
#define PHA0 0
|
||||
#define PHA1 1
|
||||
|
||||
#define SPI_CLK_12M 12000000
|
||||
#define SPI_CLK_10M 10000000
|
||||
#define SPI_CLK_4M 4000000
|
||||
|
||||
int spi0_open(uint32_t bitRate, uint8_t polarity, uint8_t phase);
|
||||
void spi0_close(void);
|
||||
int spi0_write(uint8_t *rxBuf, uint8_t *txBuf, uint8_t len);
|
||||
|
||||
int spi1_open(uint32_t bitRate, uint8_t polarity, uint8_t phase);
|
||||
void spi1_close(void);
|
||||
int spi1_write(uint8_t *rxBuf, uint8_t *txBuf, uint8_t len);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
@@ -1,168 +0,0 @@
|
||||
#include <Board.h>
|
||||
#include <ti/drivers/SPI.h>
|
||||
#include "HAL/cc2650_driver/spi_ctrl.h"
|
||||
/*
|
||||
* 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;
|
||||
static SPI_Params spiParams0;
|
||||
|
||||
static SPI_Handle spiHandle1 = NULL;
|
||||
static SPI_Params spiParams1;
|
||||
|
||||
/* Open the RTOS SPI driver */
|
||||
int spi0_open(uint32_t bitRate, uint8_t polarity, uint8_t phase)
|
||||
{
|
||||
//ret=0 -> success
|
||||
// =1 -> already exists
|
||||
// =2 -> open fail
|
||||
uint32_t rate = bitRate;
|
||||
uint8_t pol = polarity;
|
||||
uint8_t pha = phase;
|
||||
SPI_FrameFormat frameFormat;
|
||||
|
||||
|
||||
if (spiHandle0 != NULL)
|
||||
return 1;
|
||||
|
||||
if (pol == 0 && pha == 0)
|
||||
frameFormat = SPI_POL0_PHA0;
|
||||
else if (pol == 0 && pha == 1)
|
||||
frameFormat = SPI_POL0_PHA1;
|
||||
else if (pol == 1 && pha == 0)
|
||||
frameFormat = SPI_POL1_PHA0;
|
||||
else if (pol == 1 && pha == 1)
|
||||
frameFormat = SPI_POL1_PHA1;
|
||||
|
||||
/* Configure SPI as master */
|
||||
Board_initSPI();
|
||||
SPI_Params_init(&spiParams0);
|
||||
spiParams0.bitRate = rate;
|
||||
spiParams0.mode = SPI_MASTER;
|
||||
spiParams0.dataSize = 8;
|
||||
spiParams0.frameFormat = frameFormat;
|
||||
|
||||
/* Attempt to open SPI. */
|
||||
spiHandle0 = SPI_open(Board_SPI0, &spiParams0);
|
||||
|
||||
if (spiHandle0 == NULL)
|
||||
return 2;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Close the RTOS SPI driver */
|
||||
void spi0_close(void)
|
||||
{
|
||||
if (spiHandle0 != NULL)
|
||||
{
|
||||
SPI_close(spiHandle0);
|
||||
spiHandle0 = NULL;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
int spi0_write(uint8_t *rxBuf, uint8_t *txBuf, uint8_t len)
|
||||
{
|
||||
//ret=0 -> success
|
||||
// =1 -> fail
|
||||
|
||||
SPI_Transaction spi0Transaction;
|
||||
spi0Transaction.count = len;
|
||||
spi0Transaction.txBuf = txBuf;
|
||||
spi0Transaction.arg = NULL;
|
||||
spi0Transaction.rxBuf = NULL;
|
||||
|
||||
if (SPI_transfer(spiHandle0, &spi0Transaction) == FALSE) //TRUE->sucess, FALSE->fail
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Open the RTOS SPI driver */
|
||||
int spi1_open(uint32_t bitRate, uint8_t polarity, uint8_t phase)
|
||||
{
|
||||
//ret=0 -> success
|
||||
// =1 -> already exists
|
||||
// =2 -> open fail
|
||||
uint32_t rate = bitRate;
|
||||
uint8_t pol = polarity;
|
||||
uint8_t pha = phase;
|
||||
SPI_FrameFormat frameFormat;
|
||||
|
||||
Board_initSPI();
|
||||
|
||||
if (spiHandle1 != NULL)
|
||||
return 1;
|
||||
|
||||
if (pol == 0 && pha == 0)
|
||||
frameFormat = SPI_POL0_PHA0;
|
||||
else if (pol == 0 && pha == 1)
|
||||
frameFormat = SPI_POL0_PHA1;
|
||||
else if (pol == 1 && pha == 0)
|
||||
frameFormat = SPI_POL1_PHA0;
|
||||
else if (pol == 1 && pha == 1)
|
||||
frameFormat = SPI_POL1_PHA1;
|
||||
|
||||
/* Configure SPI as master */
|
||||
SPI_Params_init(&spiParams1);
|
||||
spiParams1.bitRate = rate;
|
||||
spiParams1.mode = SPI_MASTER;
|
||||
spiParams1.dataSize = 8;
|
||||
spiParams1.frameFormat = frameFormat;
|
||||
|
||||
/* Attempt to open SPI. */
|
||||
spiHandle1 = SPI_open(Board_SPI1, &spiParams1);
|
||||
|
||||
if (spiHandle1 == NULL)
|
||||
return 2;
|
||||
|
||||
return spiHandle1 != NULL;
|
||||
}
|
||||
|
||||
/* Close the RTOS SPI driver */
|
||||
void spi1_close(void)
|
||||
{
|
||||
if (spiHandle1 != NULL)
|
||||
{
|
||||
SPI_close(spiHandle1);
|
||||
spiHandle1 = NULL;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
int spi1_write(uint8_t *rxBuf, uint8_t *txBuf, uint8_t len)
|
||||
{
|
||||
//ret=0 -> success
|
||||
// =1 -> fail
|
||||
|
||||
SPI_Transaction spi1Transaction;
|
||||
spi1Transaction.count = len;
|
||||
spi1Transaction.txBuf = txBuf;
|
||||
spi1Transaction.arg = NULL;
|
||||
spi1Transaction.rxBuf = rxBuf;
|
||||
if (SPI_transfer(spiHandle1, &spi1Transaction) == FALSE) //TRUE->sucess, FALSE->fail
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -1,98 +0,0 @@
|
||||
|
||||
#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
|
||||
@@ -1,202 +0,0 @@
|
||||
#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,797 +0,0 @@
|
||||
#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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,141 @@
|
||||
#ifndef ELITE_BOARDS_SELECT_H
|
||||
#define ELITE_BOARDS_SELECT_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
|
||||
* Elite:
|
||||
* MINOR_PRODUCT_NUMBER -> 1:legacy, 2:EDC, 3:BAT, 4:EIS, 5:TRIG, 6:MEGAFLY
|
||||
*
|
||||
* +------------------------+----------------------+-------------------------+----------------+----------------------+----------------------+----------+
|
||||
* | model name | hw upper board | hw lower board | product number | device name | data server lib name | UI |
|
||||
* +------------------------+----------------------+-------------------------+----------------+----------------------+----------------------+----------+
|
||||
* | DEF_ELITE_EDC_1_4 | Elite1.4-re Jun.2019 | Elite1.4-re Jun. 2019 | 0, 2, 1, 5 | "Elite-EDC" | Elite_EDC_1.4 | null |
|
||||
* | DEF_ELITE_EDC_1_5 | Elite1.5 Dec. 2019 | Elite1.5 Dec. 2019 | 0, 2, 1, 6 | "Elite-EDC" | Elite_EDC_1.5 | EliteEDC |
|
||||
* | DEF_ELITE_EDC_1_5_RE | Elite1.5 Dec. 2019 | Elite1.5-re Jan. 2021 | 0, 2, 1, 7 | "Elite-EDC" | Elite_EDC_1.5re | EliteEDC |
|
||||
* | DEF_ELITE_EDC_1_5_R2 | Elite1.5 Dec. 2019 | Elite1.5-r2 May. 2022 | 0, 2, 1, 8 | "Elite-EDC" | Elite_EDC_1.5r2 | EliteEDC |
|
||||
* | DEF_ELITE_BAT_1_0 | Elite2.0 Feb. 2022 | 0, 3, 1, 0 | "Elite-BAT" | Elite_BAT_1.0 | EliteEDC |
|
||||
* | DEF_ELITE_EIS_1_0 | Elite1.5 Dec. 2019 | Elite EIS1.0 Aug. 2020 | 0, 4, 1, 0 | "Elite-EIS" | Elite_EIS_1.0 | EliteEIS |
|
||||
* | DEF_ELITE_EIS_1_1 | Elite1.5 Dec. 2019 | Elite EIS1.1 Feb. 2022 | 0, 4, 1, 1 | "Elite-EIS" | Elite_EIS_1.1 | EliteEIS |
|
||||
* | DEF_ELITE_EIS_MINI_1_0 | EIS MINI May. 2022 | 0, 4, 1, 2 | "Elite-EIS-MINI" | Elite_EIS_MINI_1.0 | EliteEIS |
|
||||
* | DEF_ELITE_TRIG_0_1 | Elite TRIG01 Jan. 2021 | 0, 5, 1, 0 | "Elite-TRIG" | Elite_TRIG_0.1 | null |
|
||||
* | DEF_ELITE_MEGAFLY_0_1 | 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_1_4 0
|
||||
#define DEF_ELITE_EDC_1_5 1
|
||||
#define DEF_ELITE_EDC_1_5_RE 2
|
||||
#define DEF_ELITE_EDC_1_5_R2 3
|
||||
#define DEF_ELITE_BAT_1_0 4
|
||||
#define DEF_ELITE_EIS_1_0 5
|
||||
#define DEF_ELITE_EIS_1_1 6
|
||||
#define DEF_ELITE_EIS_MINI_1_0 7
|
||||
#define DEF_ELITE_TRIG_0_1 8
|
||||
#define DEF_ELITE_MEGAFLY_0_1 9
|
||||
#define DEF_ELITE_MAX 10
|
||||
|
||||
#define DEF_ELITE_MODEL DEF_ELITE_TRIG_0_1
|
||||
#ifndef DEF_ELITE_MODEL
|
||||
#error "DEF_ELITE_MODEL not defined"
|
||||
#endif
|
||||
|
||||
#if (DEF_ELITE_MODEL == DEF_ELITE_EDC_1_4)
|
||||
#error "code no support" // need fix
|
||||
#elif (DEF_ELITE_MODEL == DEF_ELITE_EDC_1_5)
|
||||
#error "code no support" // need fix
|
||||
#elif (DEF_ELITE_MODEL == DEF_ELITE_EDC_1_5_RE)
|
||||
#include "boards_config/pin_def_edc15re.h"
|
||||
#elif (DEF_ELITE_MODEL == DEF_ELITE_EDC_1_5_R2)
|
||||
#error "code no support" // need fix
|
||||
#elif (DEF_ELITE_MODEL == DEF_ELITE_EIS_1_0)
|
||||
#error "code no support" // need fix
|
||||
#elif (DEF_ELITE_MODEL == DEF_ELITE_EIS_1_1)
|
||||
#include "boards_config/pin_def_eis11.h"
|
||||
#elif (DEF_ELITE_MODEL == DEF_ELITE_BAT_1_0)
|
||||
#error "code no support" // need fix
|
||||
#elif (DEF_ELITE_MODEL == DEF_ELITE_MEGAFLY_0_1)
|
||||
#error "code no support" // need fix
|
||||
#elif (DEF_ELITE_MODEL == DEF_ELITE_TRIG_0_1)
|
||||
#include "boards_config/pin_def_trig01.h"
|
||||
#else
|
||||
#error "no this model"
|
||||
#endif
|
||||
|
||||
|
||||
// model information
|
||||
#if (DEF_ELITE_MODEL == DEF_ELITE_EDC_1_4)
|
||||
#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_1_5)
|
||||
#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_1_5_RE)
|
||||
#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_1_5_R2)
|
||||
#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_1_0)
|
||||
#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_EIS_1_0)
|
||||
#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_1_1)
|
||||
#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_1_0)
|
||||
#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_0_1)
|
||||
#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_0_1)
|
||||
#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
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif // ELITE_BOARDS_SELECT_H
|
||||
@@ -0,0 +1,93 @@
|
||||
#ifndef PIN_DEF_TRIG01_H
|
||||
#define PIN_DEF_TRIG01_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
/*
|
||||
* +------------------------------+
|
||||
* | CC2650moda |
|
||||
* +-------------+----------------+
|
||||
* | TRIG_0 | DIO_0 |
|
||||
* | MISO | DIO_1 |
|
||||
* | TRIG_1 | DIO_2 | re: short TRIG_1 & LOAD2
|
||||
* | D0 | DIO_3 |
|
||||
* | D1 | DIO_4 |
|
||||
* | D2/JTAG_TDO | DIO_5/JTAG_TDO |
|
||||
* | D3/JTAG_TDI | DIO_6/JTAG_TDI |
|
||||
* | D4 | DIO_7 |
|
||||
* | D5 | DIO_8 |
|
||||
* | D6 | DIO_9 |
|
||||
* | D7 | DIO_10 |
|
||||
* | LOAD0 | DIO_11 |
|
||||
* | LOAD1 | DIO_12 |
|
||||
* | FLT | DIO_13 |
|
||||
* | SHUT_DOWN | DIO_14 |
|
||||
* +-------------+----------------+
|
||||
*/
|
||||
|
||||
#define CC2650_TRIG_0 DIO0
|
||||
#define CC2650_MISO DIO1
|
||||
#define CC2650_TRIG_1 DIO2
|
||||
#define CC2650_D0 DIO3
|
||||
#define CC2650_D1 DIO4
|
||||
#define CC2650_D2 DIO5
|
||||
#define CC2650_D3 DIO6
|
||||
#define CC2650_D4 DIO7
|
||||
#define CC2650_D5 DIO8
|
||||
#define CC2650_D6 DIO9
|
||||
#define CC2650_D7 DIO10
|
||||
#define CC2650_LOAD0 DIO11
|
||||
#define CC2650_LOAD1 DIO12
|
||||
#define CC2650_FLT DIO13
|
||||
#define CC2650_SHUT_DOWN DIO14
|
||||
#define CC2650_LOAD2 CC2650_TRIG_1
|
||||
|
||||
#define E_PIN_LED_SCLK_A CC2650_LOAD0, CC2650_D0
|
||||
#define E_PIN_LED_MOSI_A CC2650_LOAD0, CC2650_D1
|
||||
#define E_PIN_SCLK CC2650_LOAD0, CC2650_D2
|
||||
#define E_PIN_MOSI CC2650_LOAD0, CC2650_D3
|
||||
#define E_PIN_TW_SCKI_0 CC2650_LOAD0, CC2650_D4
|
||||
#define E_PIN_TW_SCKI_1 CC2650_LOAD0, CC2650_D5
|
||||
#define E_PIN_TW_SCKI_2 CC2650_LOAD0, CC2650_D6
|
||||
#define E_PIN_TW_SCKI_3 CC2650_LOAD0, CC2650_D7
|
||||
|
||||
#define E_PIN_BAT_CHAR CC2650_LOAD1, CC2650_D0
|
||||
#define E_PIN_BAT_OK CC2650_LOAD1, CC2650_D1
|
||||
#define E_PIN_3V_PULL_UP_DOWN_0 CC2650_LOAD1, CC2650_D2
|
||||
#define E_PIN_3V_PULL_UP_DOWN_1 CC2650_LOAD1, CC2650_D3
|
||||
#define E_PIN_OFF CC2650_LOAD1, CC2650_D4
|
||||
#define E_PIN_5V_OUT_EN_0 CC2650_LOAD1, CC2650_D5
|
||||
#define E_PIN_5V_enable CC2650_LOAD1, CC2650_D6
|
||||
#define E_PIN_5V_OUT_EN_1 CC2650_LOAD1, CC2650_D7
|
||||
|
||||
#define E_PIN_DO_MOS_0 CC2650_LOAD2, CC2650_D0
|
||||
#define E_PIN_DO_MOS_1 CC2650_LOAD2, CC2650_D1
|
||||
#define E_PIN_AO_MOS_0 CC2650_LOAD2, CC2650_D2
|
||||
#define E_PIN_AO_MOS_1 CC2650_LOAD2, CC2650_D3
|
||||
#define E_PIN_AO_MOS_2 CC2650_LOAD2, CC2650_D4
|
||||
#define E_PIN_AO_MOS_3 CC2650_LOAD2, CC2650_D5
|
||||
#define E_PIN_D0_PR_0 CC2650_LOAD2, CC2650_D6
|
||||
#define E_PIN_D0_PR_1 CC2650_LOAD2, CC2650_D7
|
||||
|
||||
/* SPI Board */
|
||||
#define Board_SPI0_MISO PIN_UNASSIGNED
|
||||
#define Board_SPI0_MOSI CC2650_D1 // load0 need to activate
|
||||
#define Board_SPI0_CLK CC2650_D0 // load0 need to activate
|
||||
#define Board_SPI0_CS PIN_UNASSIGNED
|
||||
|
||||
#define Board_SPI1_MISO CC2650_MISO
|
||||
#define Board_SPI1_MOSI CC2650_D3 // load0 need to activate
|
||||
#define Board_SPI1_CLK CC2650_D2 // load0 need to activate
|
||||
#define Board_SPI1_CS PIN_UNASSIGNED
|
||||
|
||||
/* I2C */
|
||||
#define Board_I2C0_SCL0 PIN_UNASSIGNED
|
||||
#define Board_I2C0_SDA0 PIN_UNASSIGNED
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif // PIN_DEF_TRIG01_H
|
||||
@@ -0,0 +1,26 @@
|
||||
#ifndef SPI_CTRL_H
|
||||
#define SPI_CTRL_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define SPI0 0
|
||||
#define SPI1 1
|
||||
#define SPI_POL0 0
|
||||
#define SPI_POL1 1
|
||||
#define SPI_PHA0 0
|
||||
#define SPI_PHA1 1
|
||||
|
||||
#define SPI_RATE_1M 1000000
|
||||
#define SPI_RATE_4M 4000000
|
||||
#define SPI_RATE_6M 6000000
|
||||
|
||||
uint8_t spi_open(uint8_t spi_n, uint32_t b_rate, uint8_t pol, uint8_t pha);
|
||||
uint8_t spi_close(uint8_t spi_n);
|
||||
uint8_t spi_write(uint8_t spi_n, uint8_t *rxBuf, uint8_t *txBuf, uint8_t len);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif // SPI_CTRL_H
|
||||
@@ -0,0 +1,143 @@
|
||||
#include <ti/drivers/SPI.h>
|
||||
#include "board.h"
|
||||
#include "driver/spi_ctrl.h"
|
||||
|
||||
#define CC2650_SPI_BITRATE_MAX 6e6 // Full-duplex maximum speed = 6M
|
||||
|
||||
static SPI_Handle handle0 = NULL;
|
||||
static SPI_Handle handle1 = NULL;
|
||||
|
||||
/**
|
||||
* _get_spi_mode - transfer both polarity and phase to pol_pha_combine
|
||||
* @pol: polarity
|
||||
* @pha: phase
|
||||
* Returns: spi mode
|
||||
*/
|
||||
static SPI_FrameFormat _get_spi_mode(uint8_t pol, uint8_t pha)
|
||||
{
|
||||
SPI_FrameFormat spi_mode;
|
||||
|
||||
if (pol == 0 && pha == 0)
|
||||
spi_mode = SPI_POL0_PHA0;
|
||||
else if (pol == 0 && pha == 1)
|
||||
spi_mode = SPI_POL0_PHA1;
|
||||
else if (pol == 1 && pha == 0)
|
||||
spi_mode = SPI_POL1_PHA0;
|
||||
else if (pol == 1 && pha == 1)
|
||||
spi_mode = SPI_POL1_PHA1;
|
||||
|
||||
return spi_mode;
|
||||
}
|
||||
|
||||
/**
|
||||
* spi_open -
|
||||
* @spi_n: which SPI
|
||||
* @b_rate: bit rate of SPI
|
||||
* @pol: polarity
|
||||
* @pha: phase
|
||||
* Returns: 0 on success, 1 on no this spi module, 2 on spi already open,
|
||||
* 3 on unsupported bit rate, 4 on unsupported polarity and phase,
|
||||
* while (1); on failure
|
||||
* note: Before using PIN_open() and SPI_open(), make sure that the pins are
|
||||
* not already registered, otherwise it will crash.
|
||||
*/
|
||||
uint8_t spi_open(uint8_t spi_n, uint32_t b_rate, uint8_t pol, uint8_t pha)
|
||||
{
|
||||
SPI_Params para;
|
||||
|
||||
if (spi_n >= 2)
|
||||
return 1;
|
||||
|
||||
if ((spi_n == SPI0 && handle0) || (spi_n == SPI1 && handle1))
|
||||
return 2;
|
||||
|
||||
if (b_rate > CC2650_SPI_BITRATE_MAX)
|
||||
return 3;
|
||||
|
||||
if (pol > 1 || pha > 1)
|
||||
return 4;
|
||||
|
||||
SPI_Params_init(¶);
|
||||
para.bitRate = b_rate;
|
||||
para.mode = SPI_MASTER;
|
||||
para.dataSize = 8;
|
||||
para.frameFormat = _get_spi_mode(pol, pha);
|
||||
|
||||
if (spi_n == SPI0) {
|
||||
handle0 = SPI_open(Board_SPI0, ¶);
|
||||
if (handle0 == NULL) {
|
||||
while (1);
|
||||
}
|
||||
|
||||
} else {
|
||||
handle1 = SPI_open(Board_SPI1, ¶);
|
||||
if (handle1 == NULL) {
|
||||
while (1);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* spi_close -
|
||||
* @spi_n: which SPI
|
||||
* Returns: 0 on success, 1 on no this spi module, 2 on no instance
|
||||
* note: Before using PIN_close() and SPI_close(), make sure that there is \
|
||||
* an instance available, otherwise it will crash.
|
||||
*/
|
||||
uint8_t spi_close(uint8_t spi_n)
|
||||
{
|
||||
if (spi_n >= 2)
|
||||
return 1;
|
||||
|
||||
if ((spi_n == SPI0 && !handle0) || (spi_n == SPI1 && !handle1))
|
||||
return 2;
|
||||
|
||||
if (spi_n == SPI0) {
|
||||
SPI_close(handle0);
|
||||
handle0 = NULL;
|
||||
} else {
|
||||
SPI_close(handle1);
|
||||
handle1 = NULL;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* spi_write -
|
||||
* @spi_n: which SPI
|
||||
* @*rxBuf: rxbuf
|
||||
* @*txBuf: txbuf
|
||||
* @len: what is the required length
|
||||
* Returns: 0 on success, 1 on no this spi module, 2 on no instance,
|
||||
* 3 on write failure
|
||||
*/
|
||||
uint8_t spi_write(uint8_t spi_n, uint8_t *rxBuf, uint8_t *txBuf, uint8_t len)
|
||||
{
|
||||
bool transferOK;
|
||||
SPI_Transaction spi_tran;
|
||||
|
||||
if (spi_n >= 2)
|
||||
return 1;
|
||||
|
||||
if ((spi_n == SPI0 && !handle0) || (spi_n == SPI1 && !handle1))
|
||||
return 2;
|
||||
|
||||
spi_tran.count = len;
|
||||
spi_tran.txBuf = txBuf;
|
||||
spi_tran.rxBuf = rxBuf;
|
||||
|
||||
if (spi_n == SPI0) {
|
||||
transferOK = SPI_transfer(handle0, &spi_tran);
|
||||
} else {
|
||||
transferOK = SPI_transfer(handle1, &spi_tran);
|
||||
}
|
||||
|
||||
if (!transferOK) {
|
||||
// Error in SPI or transfer already in progress.
|
||||
return 3;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
#ifndef __TIMERS_H
|
||||
#define __TIMERS_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void elite_gptimer_open(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* Copyright (c) 2015-2016, Texas Instruments Incorporated
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of Texas Instruments Incorporated nor the names of
|
||||
* its contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <ti/drivers/timer/GPTimerCC26XX.h>
|
||||
#include <xdc/runtime/Types.h>
|
||||
#include <ti/sysbios/BIOS.h>
|
||||
#include "board.h"
|
||||
#include "driver/timers.h"
|
||||
#include "service/app_ser.h"
|
||||
|
||||
#define CLOCK_FREQ 4769 // clock freq = 0.1 ms(4800), Measured(4769)
|
||||
|
||||
static void __timerCallback(GPTimerCC26XX_Handle handle, GPTimerCC26XX_IntMask interruptMask)
|
||||
{
|
||||
// interrupt callback code goes here. Minimize processing in interrupt.
|
||||
elite_100us_task();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void elite_gptimer_open(void)
|
||||
{
|
||||
GPTimerCC26XX_Handle hTimer;
|
||||
GPTimerCC26XX_Params params;
|
||||
GPTimerCC26XX_Params_init(¶ms);
|
||||
params.width = GPT_CONFIG_16BIT;
|
||||
params.mode = GPT_MODE_PERIODIC_UP;
|
||||
params.debugStallMode = GPTimerCC26XX_DEBUG_STALL_OFF;
|
||||
hTimer = GPTimerCC26XX_open(Board_GPTIMER0A, ¶ms);
|
||||
if (hTimer == NULL) {
|
||||
Task_exit();
|
||||
}
|
||||
|
||||
Types_FreqHz freq;
|
||||
BIOS_getCpuFreq(&freq);
|
||||
//GPTimerCC26XX_Value loadVal = freq.lo / 1000 - 1; //47999 = 1ms
|
||||
GPTimerCC26XX_Value loadVal = CLOCK_FREQ; //0.1ms
|
||||
GPTimerCC26XX_setLoadValue(hTimer, loadVal);
|
||||
GPTimerCC26XX_registerInterrupt(hTimer, __timerCallback, GPT_INT_TIMEOUT);
|
||||
GPTimerCC26XX_start(hTimer);
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
/*=============================================================================
|
||||
= EliteCorrection.h =
|
||||
=============================================================================*/
|
||||
#ifndef EliteCorrection
|
||||
#define EliteCorrection
|
||||
|
||||
#define BOARD_E7A4
|
||||
|
||||
struct formula_ctx_t
|
||||
{
|
||||
long long coeff;
|
||||
long long offset;
|
||||
};
|
||||
|
||||
struct correction_ctx_t
|
||||
{
|
||||
struct formula_ctx_t Usercode2Aout[4];
|
||||
};
|
||||
|
||||
#ifdef BOARD_EE59 // Elite trigger
|
||||
struct correction_ctx_t Correction = {
|
||||
|
||||
.Usercode2Aout[0].coeff = 9544555,
|
||||
.Usercode2Aout[0].offset = 624861853,
|
||||
|
||||
.Usercode2Aout[1].coeff = 9544555,
|
||||
.Usercode2Aout[1].offset = 624861853,
|
||||
|
||||
.Usercode2Aout[2].coeff = 9544555,
|
||||
.Usercode2Aout[2].offset = 624861853,
|
||||
|
||||
.Usercode2Aout[3].coeff = 9544555,
|
||||
.Usercode2Aout[3].offset = 624861853,
|
||||
};
|
||||
#endif
|
||||
|
||||
#ifdef BOARD_E7A4 // Elite trigger
|
||||
struct correction_ctx_t Correction = {
|
||||
|
||||
.Usercode2Aout[0].coeff = 9603806,
|
||||
.Usercode2Aout[0].offset = 284189190,
|
||||
|
||||
.Usercode2Aout[1].coeff = 9716008,
|
||||
.Usercode2Aout[1].offset = 231112610,
|
||||
|
||||
.Usercode2Aout[2].coeff = 9617383,
|
||||
.Usercode2Aout[2].offset = 82131390,
|
||||
|
||||
.Usercode2Aout[3].coeff = 9688579,
|
||||
.Usercode2Aout[3].offset = 469137665,
|
||||
};
|
||||
#endif
|
||||
|
||||
#ifdef BOARD_EEA9 // Elite trigger
|
||||
struct correction_ctx_t Correction = {
|
||||
|
||||
.Usercode2Aout[0].coeff = 9647437,
|
||||
.Usercode2Aout[0].offset = 137525701,
|
||||
|
||||
.Usercode2Aout[1].coeff = 9675906,
|
||||
.Usercode2Aout[1].offset = 490863999,
|
||||
|
||||
.Usercode2Aout[2].coeff = 9668886,
|
||||
.Usercode2Aout[2].offset = 94793912,
|
||||
|
||||
.Usercode2Aout[3].coeff = 9717771,
|
||||
.Usercode2Aout[3].offset = 94763422,
|
||||
};
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -1,15 +1,9 @@
|
||||
|
||||
#ifndef VERSION_DATE
|
||||
#define VERSION_DATE
|
||||
|
||||
#define VERSION_DATE_YEAR 23
|
||||
#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 !!
|
||||
// it's the last version hash
|
||||
#define VERSION_HASH 8808490caa465cc94d14896de28763a5e5c4672b
|
||||
#define VERSION_GIT_BRANCH Elite_OBJ_0.2mv
|
||||
#define VERSION_DATE_YEAR 24
|
||||
#define VERSION_DATE_MONTH 1
|
||||
#define VERSION_DATE_DAY 8
|
||||
#define VERSION_DATE_HOUR 17
|
||||
#define VERSION_DATE_MINUTE 41
|
||||
#endif
|
||||
|
||||
@@ -248,47 +248,46 @@ int main()
|
||||
void AssertHandler(uint8 assertCause, uint8 assertSubcause)
|
||||
{
|
||||
// Open the display if the app has not already done so
|
||||
// if ( !dispHandle )
|
||||
// {
|
||||
// dispHandle = Display_open(Display_Type_LCD, NULL);
|
||||
// }
|
||||
// if ( !dispHandle )
|
||||
// {
|
||||
// dispHandle = Display_open(Display_Type_LCD, NULL);
|
||||
// }
|
||||
|
||||
// Display_print0(dispHandle, 0, 0, ">>>STACK ASSERT");
|
||||
|
||||
// Display_print0(dispHandle, 0, 0, ">>>STACK ASSERT");
|
||||
// // check the assert cause
|
||||
// switch (assertCause)
|
||||
// {
|
||||
// case HAL_ASSERT_CAUSE_OUT_OF_MEMORY:
|
||||
// Display_print0(dispHandle, 0, 0, "***ERROR***");
|
||||
// Display_print0(dispHandle, 2, 0, ">> OUT OF MEMORY!");
|
||||
// break;
|
||||
|
||||
// check the assert cause
|
||||
// switch (assertCause)
|
||||
// {
|
||||
// case HAL_ASSERT_CAUSE_OUT_OF_MEMORY:
|
||||
// Display_print0(dispHandle, 0, 0, "***ERROR***");
|
||||
// Display_print0(dispHandle, 2, 0, ">> OUT OF MEMORY!");
|
||||
// break;
|
||||
//
|
||||
// case HAL_ASSERT_CAUSE_INTERNAL_ERROR:
|
||||
// // check the subcause
|
||||
// if (assertSubcause == HAL_ASSERT_SUBCAUSE_FW_INERNAL_ERROR)
|
||||
// {
|
||||
// Display_print0(dispHandle, 0, 0, "***ERROR***");
|
||||
// Display_print0(dispHandle, 2, 0, ">> INTERNAL FW ERROR!");
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// Display_print0(dispHandle, 0, 0, "***ERROR***");
|
||||
// Display_print0(dispHandle, 2, 0, ">> INTERNAL ERROR!");
|
||||
// }
|
||||
// break;
|
||||
//
|
||||
// case HAL_ASSERT_CAUSE_ICALL_ABORT:
|
||||
// Display_print0(dispHandle, 0, 0, "***ERROR***");
|
||||
// Display_print0(dispHandle, 2, 0, ">> ICALL ABORT!");
|
||||
// HAL_ASSERT_SPINLOCK;
|
||||
// break;
|
||||
//
|
||||
// default:
|
||||
// Display_print0(dispHandle, 0, 0, "***ERROR***");
|
||||
// Display_print0(dispHandle, 2, 0, ">> DEFAULT SPINLOCK!");
|
||||
// HAL_ASSERT_SPINLOCK;
|
||||
// }
|
||||
// case HAL_ASSERT_CAUSE_INTERNAL_ERROR:
|
||||
// // check the subcause
|
||||
// if (assertSubcause == HAL_ASSERT_SUBCAUSE_FW_INERNAL_ERROR)
|
||||
// {
|
||||
// Display_print0(dispHandle, 0, 0, "***ERROR***");
|
||||
// Display_print0(dispHandle, 2, 0, ">> INTERNAL FW ERROR!");
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// Display_print0(dispHandle, 0, 0, "***ERROR***");
|
||||
// Display_print0(dispHandle, 2, 0, ">> INTERNAL ERROR!");
|
||||
// }
|
||||
// break;
|
||||
|
||||
// case HAL_ASSERT_CAUSE_ICALL_ABORT:
|
||||
// Display_print0(dispHandle, 0, 0, "***ERROR***");
|
||||
// Display_print0(dispHandle, 2, 0, ">> ICALL ABORT!");
|
||||
// HAL_ASSERT_SPINLOCK;
|
||||
// break;
|
||||
|
||||
// default:
|
||||
// Display_print0(dispHandle, 0, 0, "***ERROR***");
|
||||
// Display_print0(dispHandle, 2, 0, ">> DEFAULT SPINLOCK!");
|
||||
// HAL_ASSERT_SPINLOCK;
|
||||
// }
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
#ifndef LED_APA_102_H
|
||||
#define LED_APA_102_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*
|
||||
* APA-102-2020-256-8A-20190612: Series data structure
|
||||
* +-------------------+------------------------- ... -+-----------------+
|
||||
* | start_frame(4B) | led_frame(4B) *LED_TANDEM_N | end_frame(4B) |
|
||||
* +-------------------+------------------------- ... -+-----------------+
|
||||
* / \
|
||||
* / led_frame(4B) \
|
||||
* / \
|
||||
* 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
|
||||
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
* | 111 | bright | blue | green | red |
|
||||
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
*/
|
||||
|
||||
#include "driver/spi_ctrl.h"
|
||||
|
||||
#define DEF_LED_TANDEN_N 8
|
||||
|
||||
#ifdef DEF_LED_TANDEN_N
|
||||
#define LED_TANDEM_N DEF_LED_TANDEN_N
|
||||
#else
|
||||
#define LED_TANDEM_N 12
|
||||
#endif
|
||||
|
||||
enum led_series_nb_e {
|
||||
LED_NB_1 = 0,
|
||||
LED_NB_2,
|
||||
LED_NB_3,
|
||||
LED_NB_4,
|
||||
LED_NB_5,
|
||||
LED_NB_6,
|
||||
LED_NB_7,
|
||||
LED_NB_8,
|
||||
LED_NB_9,
|
||||
LED_NB_10,
|
||||
LED_NB_11,
|
||||
LED_NB_12,
|
||||
|
||||
LED_NB_MAX = LED_TANDEM_N,
|
||||
};
|
||||
|
||||
enum led_bright_e {
|
||||
LED_BR_LV0 = 0x00,
|
||||
LED_BR_LV1 = 0x01,
|
||||
LED_BR_LV8 = 0x08,
|
||||
|
||||
LED_BR_MAX = 0x1F,
|
||||
};
|
||||
|
||||
enum led_color_e {
|
||||
LED_CLR_BLACK = 0,
|
||||
LED_CLR_WHITE,
|
||||
LED_CLR_RED,
|
||||
LED_CLR_ORANGE,
|
||||
LED_CLR_YELLOW,
|
||||
LED_CLR_GREEN,
|
||||
LED_CLR_CYAN,
|
||||
LED_CLR_BLUE,
|
||||
LED_CLR_PURPLE,
|
||||
LED_CLR_MAGENTA,
|
||||
LED_CLR_YELLOWGREEN,
|
||||
LED_CLR_EMERALD,
|
||||
LED_CLR_LOW_BAT,
|
||||
|
||||
LED_CLR_MAX,
|
||||
};
|
||||
|
||||
struct led_color_t {
|
||||
uint8_t b;
|
||||
uint8_t g;
|
||||
uint8_t r;
|
||||
};
|
||||
|
||||
int led_color_set(enum led_series_nb_e led_nb, enum led_bright_e bright, enum led_color_e color);
|
||||
int led_color_code_set(enum led_series_nb_e led_nb, enum led_bright_e bright, struct led_color_t *color);
|
||||
int led_rainbow(enum led_bright_e bright);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif // LED_APA_102_H
|
||||
@@ -0,0 +1,149 @@
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include "module/led_APA_102.h"
|
||||
|
||||
#define LED_FRAME_RSVD 0x07 // 0x11100000 || bright
|
||||
#define LED_SERIES_D_START 0x00000000
|
||||
#define LED_SERIES_D_END 0xFFFFFFFF
|
||||
|
||||
struct led_frame_t {
|
||||
uint8_t bright: 5,
|
||||
rsvd: 3;
|
||||
struct led_color_t color;
|
||||
};
|
||||
|
||||
struct led_series_data_t {
|
||||
uint32_t f_start;
|
||||
struct led_frame_t f_led[LED_TANDEM_N];
|
||||
uint32_t f_end;
|
||||
};
|
||||
|
||||
const struct led_color_t led_color_list_g[LED_CLR_MAX] = {
|
||||
// {blue, green, red}
|
||||
{0x00, 0x00, 0x00}, // LED_CLR_BLACK
|
||||
{0xFF, 0xFF, 0xCA}, // LED_CLR_WHITE
|
||||
{0x00, 0x00, 0xFF}, // LED_CLR_RED
|
||||
{0x09, 0x58, 0xFF}, // LED_CLR_ORANGE
|
||||
{0x00, 0xE1, 0xE1}, // LED_CLR_YELLOW
|
||||
{0x00, 0xFA, 0x00}, // LED_CLR_GREEN
|
||||
{0x40, 0x40, 0x00}, // LED_CLR_CYAN
|
||||
{0xAA, 0x00, 0x00}, // LED_CLR_BLUE
|
||||
{0x6F, 0x00, 0x3A}, // LED_CLR_PURPLE
|
||||
{0xFF, 0x00, 0xFF}, // LED_CLR_MAGENTA
|
||||
{0x00, 0xA6, 0x64}, // LED_CLR_YELLOWGREEN
|
||||
{0x78, 0xC8, 0x50}, // LED_CLR_EMERALD
|
||||
{0x05, 0x35, 0x9E}, // LED_CLR_LOW_BAT (orange)
|
||||
};
|
||||
|
||||
static int __led_complete(struct led_series_data_t *sd)
|
||||
{
|
||||
for (int i = LED_NB_1; i < LED_NB_MAX; i++)
|
||||
sd->f_led[i].rsvd = LED_FRAME_RSVD;
|
||||
|
||||
sd->f_start = LED_SERIES_D_START;
|
||||
sd->f_end = LED_SERIES_D_END;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int __led_color_set(enum led_series_nb_e led_nb, struct led_frame_t *led_f)
|
||||
{
|
||||
static struct led_series_data_t led_series_data_g = {0};
|
||||
struct led_series_data_t *sd = &led_series_data_g;
|
||||
|
||||
/*
|
||||
* led_nb - < LED_NB_MAX: fill one led_frame
|
||||
* == LED_NB_MAX: fill multiple led_frame
|
||||
*
|
||||
* complete: then, fill (start_frame, end_frame and the rsvd of every led_frame)
|
||||
*
|
||||
* finally, write cmd to hw by spi
|
||||
*/
|
||||
if (led_nb < LED_NB_MAX) {
|
||||
memcpy(&sd->f_led[led_nb], led_f, sizeof(struct led_frame_t));
|
||||
} else if (led_nb == LED_NB_MAX) {
|
||||
for (enum led_series_nb_e i = LED_NB_1; i < LED_NB_MAX; i++) {
|
||||
memcpy(&sd->f_led[i], led_f, sizeof(struct led_frame_t));
|
||||
}
|
||||
}
|
||||
__led_complete(sd);
|
||||
|
||||
spi_open(SPI0, SPI_RATE_1M, SPI_POL0, SPI_PHA1); //SPI 1M: LED
|
||||
led_cs(1);
|
||||
spi_write(SPI0, NULL, (uint8_t *)sd, sizeof(struct led_series_data_t));
|
||||
led_cs(0);
|
||||
spi_close(SPI0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int led_color_set(enum led_series_nb_e led_nb, enum led_bright_e bright, enum led_color_e color)
|
||||
{
|
||||
struct led_frame_t led_f = {0};
|
||||
|
||||
if (led_nb > LED_NB_MAX)
|
||||
return -1;
|
||||
|
||||
if (bright > LED_BR_MAX)
|
||||
return -2;
|
||||
|
||||
if (color >= LED_CLR_MAX)
|
||||
return -3;
|
||||
|
||||
led_f.bright = bright;
|
||||
led_f.color = led_color_list_g[color];
|
||||
__led_color_set(led_nb, &led_f);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int led_color_code_set(enum led_series_nb_e led_nb, enum led_bright_e bright, struct led_color_t *color)
|
||||
{
|
||||
struct led_frame_t led_f = {0};
|
||||
|
||||
if (led_nb > LED_NB_MAX)
|
||||
return -1;
|
||||
|
||||
if (bright > LED_BR_MAX)
|
||||
return -2;
|
||||
|
||||
led_f.bright = bright;
|
||||
memcpy(&led_f.color, &color, sizeof(struct led_color_t));
|
||||
__led_color_set(led_nb, &led_f);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int led_rainbow(enum led_bright_e bright)
|
||||
{
|
||||
if (bright > LED_BR_MAX)
|
||||
return -1;
|
||||
|
||||
for(enum led_series_nb_e i=LED_NB_1; i<LED_NB_MAX; i++)
|
||||
led_color_set(i, bright, (enum led_color_e)i);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* example -
|
||||
* customize color:
|
||||
* struct led_color_t led_c;
|
||||
* uint8_t bri;
|
||||
* // { ins, ins, num, r, g, b, bri};
|
||||
* uint8_t ins[20] = {0x30, 0x00, LED_NB_4, 0xFF, 0x00, 0x44, 0x3};
|
||||
* led_c.r = ins[3];
|
||||
* led_c.g = ins[4];
|
||||
* led_c.b = ins[5];
|
||||
* bri = ins[6];
|
||||
* led_color_code_set(LED_NB_4, bri, led_c);
|
||||
*
|
||||
* single led:
|
||||
* led_color_set(LED_NB_1, LED_BR_LV1, LED_CLR_WHITE);
|
||||
*
|
||||
* multiple led:
|
||||
* led_color_set(LED_NB_MAX, LED_BR_LV1, LED_CLR_BLUE);
|
||||
*
|
||||
* rainbow led:
|
||||
* led_rainbow(LED_BR_LV1);
|
||||
*/
|
||||
@@ -0,0 +1,33 @@
|
||||
# $python .\simplelink\ble_sdk_2_02_02_25\src\examples\simple_peripheral\cc26xx\app\python\update_elite_version.py
|
||||
|
||||
import datetime
|
||||
import os
|
||||
|
||||
print(datetime.datetime.now())
|
||||
# print(datetime.datetime.now().year)
|
||||
# print(datetime.datetime.now().month)
|
||||
# print(datetime.datetime.now().day)
|
||||
# print(datetime.datetime.now().hour)
|
||||
# print(datetime.datetime.now().minute)
|
||||
# print(datetime.datetime.now().strftime("%H:%M:%S"))
|
||||
|
||||
y = datetime.datetime.now().year % 100
|
||||
m = datetime.datetime.now().month
|
||||
d = datetime.datetime.now().day
|
||||
hour = datetime.datetime.now().hour
|
||||
minute = datetime.datetime.now().minute
|
||||
|
||||
path = os.getcwd()
|
||||
path += '/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/Elite_version.h'
|
||||
print('save:', path)
|
||||
|
||||
with open(path, 'w') as f:
|
||||
f.write('#ifndef VERSION_DATE' + '\n')
|
||||
f.write('#define VERSION_DATE' + '\n\n')
|
||||
f.write('#define VERSION_DATE_YEAR ' + str(y) + '\n')
|
||||
f.write('#define VERSION_DATE_MONTH ' + str(m) + '\n')
|
||||
f.write('#define VERSION_DATE_DAY ' + str(d) + '\n')
|
||||
f.write('#define VERSION_DATE_HOUR ' + str(hour) + '\n')
|
||||
f.write('#define VERSION_DATE_MINUTE ' + str(minute) + '\n')
|
||||
|
||||
f.write('#endif' + '\n')
|
||||
@@ -0,0 +1,274 @@
|
||||
#ifndef APP_SER_H
|
||||
#define APP_SER_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct elite_instru_t
|
||||
{
|
||||
uint8_t memoryboard_id;
|
||||
uint8_t elite_mode;
|
||||
|
||||
// time relation
|
||||
uint32_t vscan_rate;
|
||||
uint32_t notify_rate;
|
||||
|
||||
/** TRIG output channel **/
|
||||
bool tri_d0_as_5v_en;
|
||||
bool tri_d1_as_5v_en;
|
||||
|
||||
/** trigger mode enable **/
|
||||
bool trig0_en;
|
||||
bool trig1_en;
|
||||
uint8_t trig0_edge;
|
||||
uint8_t trig1_edge;
|
||||
|
||||
// about a0~a3
|
||||
uint16_t Trig_CurCon[4];
|
||||
};
|
||||
|
||||
#include "Elite_version.h"
|
||||
#include "driver/timers.h"
|
||||
#include "driver/spi_ctrl.h"
|
||||
#include "module/led_APA_102.h"
|
||||
#include "service/mode_all_output_ctrl.h"
|
||||
|
||||
// LED
|
||||
#define LED_BT_WAIT 0x01
|
||||
#define LED_NO_EVENT 0x02
|
||||
#define LED_WORKING 0x04
|
||||
static uint8_t led_status = LED_NO_EVENT;
|
||||
static void update_led(uint8_t led);
|
||||
|
||||
/**
|
||||
* Trigger channel initialize
|
||||
*/
|
||||
#define PIN_PR0 0
|
||||
#define PIN_D0_SW 1
|
||||
#define PIN_A0 2
|
||||
#define PIN_A2 3
|
||||
#define PIN_A3 4
|
||||
#define PIN_A1 5
|
||||
#define PIN_D1_SW 6
|
||||
#define PIN_PR1 7
|
||||
#define PIN_D0_5V 8
|
||||
#define PIN_D1_5V 9
|
||||
#define PIN_OUT_CH_MAX 10
|
||||
bool chan_en[PIN_OUT_CH_MAX]; // [pr0_en, d0_mos_en, a0_en, a2_en, a3_en,
|
||||
// a1_en, d1_mos_en, pr1_en, d0_5v_en, d1_5v_en]
|
||||
|
||||
|
||||
/** TRIG01 trigger edge type **/
|
||||
#define TRIG_POSEDGE 0x00
|
||||
#define TRIG_NEGEDGE 0x01
|
||||
#define TRIG_BOTHEDGE 0x02
|
||||
#define TRIG_DIS 0x03
|
||||
// define BT instruction
|
||||
#define INS_TYPE_RIS 0x30
|
||||
#define INS_TYPE_VIS 0xC0
|
||||
#define INS_TYPE_CIS 0x70
|
||||
|
||||
// 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
|
||||
|
||||
//clock
|
||||
/***************************************************
|
||||
* Q: Why define CPU_1us = 16?
|
||||
* A:
|
||||
* 3 cycles per loop: 16 loops @ 48 Mhz ~= 1 us
|
||||
* 3 cycles * X loops / 48Mhz = 1us(ideal value)
|
||||
* 3 cycles * X loops / 48us = 1us(ideal value)
|
||||
* X = 48 / 3 => X = 16 loops
|
||||
***************************************************/
|
||||
#define CPU_1us 16
|
||||
#define CPU_1ms 16000
|
||||
|
||||
// Elite TRIG01 ADC command
|
||||
#define CMD_DOUT_5V_IMON_0 0xC5
|
||||
#define CMD_DOUT_5V_IMON_1 0xD5
|
||||
|
||||
#define Aout_CH_0 0x00
|
||||
#define Aout_CH_1 0x01
|
||||
#define Aout_CH_2 0x02
|
||||
#define Aout_CH_3 0x03
|
||||
|
||||
|
||||
|
||||
#define LATCH_BUFF_SIZE 8 // define latch
|
||||
|
||||
// CIS (control instruction)
|
||||
#define CIS_VERSION 0x40
|
||||
#define CIS_VOLT 0x10
|
||||
#define CIS_TEMPERATURE 0x80
|
||||
|
||||
/* TRIG01 define */
|
||||
#define TRIG_PR 0x00
|
||||
#define TRIG_MOS_DOUT 0x01
|
||||
#define TRIG_MOS_AOUT 0x02
|
||||
#define TRIG_5V_OUT 0x03
|
||||
#define TRIG_input 0x04
|
||||
// #define TRIG_CHAN_COUNT 10 // channel count of TRIG01
|
||||
|
||||
|
||||
|
||||
// gptimer
|
||||
struct gptimer_t
|
||||
{
|
||||
uint32_t gpt_now;
|
||||
uint32_t gpt_last;
|
||||
uint8_t gpt_delta;
|
||||
};
|
||||
|
||||
/* member of mode */
|
||||
struct wm_aout_ctx_t
|
||||
{
|
||||
int32_t _Vset;
|
||||
int32_t _Curset0;
|
||||
int32_t _Curset1;
|
||||
int32_t _Curset2;
|
||||
int32_t _Curset3;
|
||||
};
|
||||
|
||||
/* member of mode */
|
||||
#define CH_PR0 0
|
||||
#define CH_D0 1
|
||||
#define CH_A0 2
|
||||
#define CH_A2 3
|
||||
#define CH_A3 4
|
||||
#define CH_A1 5
|
||||
#define CH_D1 6
|
||||
#define CH_PR1 7
|
||||
|
||||
|
||||
/**
|
||||
* Latch initialize
|
||||
*/
|
||||
struct _LH
|
||||
{
|
||||
bool LATCH0[LATCH_BUFF_SIZE];
|
||||
bool LATCH1[LATCH_BUFF_SIZE];
|
||||
bool LATCH2[LATCH_BUFF_SIZE];
|
||||
};
|
||||
|
||||
// RIS (real instruction)
|
||||
enum all_mode_e
|
||||
{
|
||||
MODE_ANALOG_CURRENT_CTRL = 0x0E, // 0x0E
|
||||
MODE_ALL_OUTPUT_CTRL = 0x0F, // 0x0F
|
||||
DEV_TEST = 0xFF, // 0xFF,
|
||||
SET_SAMPLE_RATE = 0xE0, // 0xE0,
|
||||
SET_EN_CHAN = 0x81, // 0x81,
|
||||
SET_PARA = 0xE2, // 0xE2,
|
||||
SET_TRIG_EN = 0x41 // 0x41,
|
||||
};
|
||||
|
||||
enum dev_para_e
|
||||
{
|
||||
VERSION_DEV_TEST = 0x01,
|
||||
BAT_DEV_TEST = 0x02,
|
||||
TEMP_DEV_TEST = 0x03,
|
||||
LED_DEV_TEST = 0x04,
|
||||
AOUT_DEV_TEST = 0x05,
|
||||
DOUT_DEV_TEST = 0x06,
|
||||
PR_DEV_TEST = 0x07,
|
||||
OUT_5VEN_DEV_TEST = 0x08,
|
||||
SET_EN_CHAN_DEV_TEST = 0x0F,
|
||||
VIS_DEV_TRIG_EN = 0x09,
|
||||
Init_DEV_Trig_flag = 0x0A
|
||||
};
|
||||
|
||||
enum set_para_e
|
||||
{
|
||||
AOUT_CURRENT = 0x02,
|
||||
};
|
||||
|
||||
struct _LH LH = { 0 };
|
||||
struct elite_instru_t instru = { 0 };
|
||||
struct gptimer_t gpt = {0};
|
||||
static int32_t notify_ch1 = 0;
|
||||
static int32_t notify_ch2 = 0;
|
||||
static int32_t notify_ch3 = 0;
|
||||
static int32_t notify_ch4 = 0;
|
||||
static int32_t notify_ch5 = 0;
|
||||
static int32_t notify_ch6 = 0;
|
||||
static uint16_t NotifyVoltBat = 2000; //0x07d0
|
||||
static uint16_t NotifyTemperature = 200; //0x00c8
|
||||
static uint16_t NotifyCycleNumber = 0;
|
||||
static bool trig0_event_wait = false;
|
||||
static bool trig1_event_wait = false;
|
||||
static bool dual_trig_mode = false;
|
||||
static bool single_trig_mode = false;
|
||||
static void *workMode_p = NULL;
|
||||
/* Trigger Flag */
|
||||
static bool trig_PeriodicEvent = false;
|
||||
static bool TRIG_TrigEnable = false;
|
||||
static bool Trig_receive = false;
|
||||
static bool trig0_event = false;
|
||||
static bool trig1_event = false;
|
||||
static bool FLT_event = false;
|
||||
static bool PeriodicEvent = false;
|
||||
static bool mode_init;
|
||||
static bool finishMode = false;
|
||||
PIN_Handle PinHandle;
|
||||
static PIN_State PinStatus;
|
||||
|
||||
const PIN_Config Elite_pin[] = {
|
||||
CC2650_LOAD0 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL,
|
||||
CC2650_LOAD1 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL,
|
||||
CC2650_LOAD2 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL,
|
||||
CC2650_SHUT_DOWN | PIN_INPUT_EN | PIN_PULLDOWN, // to sense switch
|
||||
CC2650_TRIG_0 | PIN_INPUT_EN | PIN_PULLDOWN,
|
||||
CC2650_FLT | PIN_INPUT_EN | PIN_PULLDOWN,
|
||||
// CC2650_TRIG_1 | PIN_INPUT_EN | PIN_PULLDOWN,
|
||||
PIN_TERMINATE
|
||||
};
|
||||
|
||||
void elite_100us_task(void);
|
||||
|
||||
|
||||
static void InitEliteInstruction(void);
|
||||
static void set_channel_led(bool *chan_en);
|
||||
static void elite_reset();
|
||||
static void SendNotify();
|
||||
static void FlushNotify();
|
||||
static void key_manage(uint32_t delta_time);
|
||||
static uint8_t pin_button_get(void);
|
||||
static bool power_on(uint32_t delta_time);
|
||||
static void GPT_timerIncrement();
|
||||
static uint16_t Aout_decode(uint16_t input_code);
|
||||
static void set_Aoutput(uint8_t GPIO_channel, uint16_t input_code);
|
||||
static void TW1508reset();
|
||||
static void curr_out();
|
||||
static void aout_Curscan(void);
|
||||
static uint16_t Usercode_Correction_to_Aout(uint8_t aout_chan, uint16_t usercode);
|
||||
static void device_init();
|
||||
static void send_device_info();
|
||||
static void set_para(uint8_t elite_mode, uint16_t parameter, int32_t value);
|
||||
static void chg_aout_para(uint16_t parameter, int32_t value);
|
||||
static void trig_event_flush();
|
||||
static void trig_callback(PIN_Handle handle, PIN_Id pinId);
|
||||
static void trig_sense();
|
||||
static void trig_en_check();
|
||||
static void InitTrigChan();
|
||||
static void PIN_trig_edge_set(uint8_t trig0_edge, uint8_t trig1_edge);
|
||||
static void GPIO_SPI_transfer(uint32_t *GPIO_CLK_CH, uint16_t spi_GPIO_txbuf);
|
||||
static void led_cs(uint8_t signal);
|
||||
static void disable_trig_output();
|
||||
static void PIN15_setOutputValue_refresh();
|
||||
static void PIN15_setOutputValue(uint32_t latch_num, uint32_t pin_num, bool highlow);
|
||||
static void update_latch_status(uint32_t latch_num, uint32_t elite_pin, bool highlow);
|
||||
static void remove_elite_pin();
|
||||
static void add_elite_pin();
|
||||
static int wm_deinit(void);
|
||||
static void *wm_get(void);
|
||||
static void receive_instruction(uint8 *recv_instru);
|
||||
static void elite_task(void);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif // APP_SER_H
|
||||
@@ -0,0 +1,15 @@
|
||||
#ifndef __MODE_ALL_OUTPUT_CTRL_H
|
||||
#define __MODE_ALL_OUTPUT_CTRL_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void all_output_ctrl_mode_vsan(uint32_t delta_t);
|
||||
int all_output_ctrl_mode_create(void);
|
||||
void handle_all_output_mode_instru(uint8_t *recv_instru, struct elite_instru_t *instruction);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
@@ -0,0 +1,294 @@
|
||||
#include <stdint.h>
|
||||
#include "service/mode_all_output_ctrl.h"
|
||||
|
||||
struct ch_all_out_ctrl_ctx_t
|
||||
{
|
||||
// user setting
|
||||
uint8_t used: 1,
|
||||
v_early: 1,
|
||||
v_mid: 4,
|
||||
v_late: 1,
|
||||
v_rsvd: 1;
|
||||
uint32_t t_early;
|
||||
uint32_t t_mid[4];
|
||||
uint32_t t_late;
|
||||
uint16_t cycle;
|
||||
|
||||
// automatic setting
|
||||
uint32_t t_part[4];
|
||||
uint32_t t_period;
|
||||
uint8_t init: 1,
|
||||
t_early_period: 1,
|
||||
t_mid_period: 1,
|
||||
t_late_period: 1,
|
||||
rsvd: 4;
|
||||
uint32_t v_scan_rate;
|
||||
};
|
||||
|
||||
struct mode_all_out_ctrl_ctx_t
|
||||
{
|
||||
struct ch_all_out_ctrl_ctx_t channel[8];
|
||||
};
|
||||
|
||||
void __all_output_ctrl_mode_ch_vsan(struct ch_all_out_ctrl_ctx_t *channel, uint32_t delta_t, uint8_t ch)
|
||||
{
|
||||
uint32_t m;
|
||||
|
||||
if (!channel->used)
|
||||
return;
|
||||
|
||||
if (channel->init) {
|
||||
channel->v_scan_rate = 0;
|
||||
channel->init = false;
|
||||
}
|
||||
|
||||
channel->v_scan_rate += delta_t;
|
||||
|
||||
if (channel->t_early_period) {
|
||||
if (ch==CH_D0 && instru.tri_d0_as_5v_en==1) {
|
||||
if(channel->v_early) {
|
||||
chan_en[CH_D0] = 0;
|
||||
chan_en[8] = 0;
|
||||
} else {
|
||||
chan_en[CH_D0] = 0;
|
||||
chan_en[8] = 1;
|
||||
}
|
||||
} else if (ch==CH_D1 && instru.tri_d1_as_5v_en==1) {
|
||||
if(channel->v_early) {
|
||||
chan_en[CH_D1] = 0;
|
||||
chan_en[9] = 0;
|
||||
} else {
|
||||
chan_en[CH_D1] = 0;
|
||||
chan_en[9] = 1;
|
||||
}
|
||||
} else {
|
||||
chan_en[ch] = channel->v_early;
|
||||
}
|
||||
|
||||
if (channel->v_scan_rate >= channel->t_early) {
|
||||
channel->v_scan_rate -= channel->t_early; //To get right time
|
||||
channel->t_early_period = false;
|
||||
channel->t_mid_period = true;
|
||||
channel->v_scan_rate = 0;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (channel->t_mid_period) {
|
||||
if (channel->v_scan_rate >= channel->t_period) {
|
||||
channel->v_scan_rate -= channel->t_period; //To get right time
|
||||
channel->cycle--;
|
||||
if (channel->cycle == 0) {
|
||||
channel->t_mid_period = false;
|
||||
channel->t_late_period = true;
|
||||
channel->v_scan_rate = 0;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
m = channel->v_scan_rate ? (channel->v_scan_rate % channel->t_period) : 0;
|
||||
|
||||
for(int i=0; i<4; i++) {
|
||||
if (m < channel->t_part[i]) {
|
||||
if (ch == CH_D0 && instru.tri_d0_as_5v_en==1) {
|
||||
if(channel->v_mid & (1 << i)) {
|
||||
chan_en[CH_D0] = 0;
|
||||
chan_en[8] = 0;
|
||||
} else {
|
||||
chan_en[CH_D0] = 0;
|
||||
chan_en[8] = 1;
|
||||
}
|
||||
} else if (ch == CH_D1 && instru.tri_d1_as_5v_en==1) {
|
||||
if(channel->v_mid & (1 << i)) {
|
||||
chan_en[CH_D1] = 0;
|
||||
chan_en[9] = 0;
|
||||
} else {
|
||||
chan_en[CH_D1] = 0;
|
||||
chan_en[9] = 1;
|
||||
}
|
||||
} else {
|
||||
chan_en[ch] = channel->v_mid & (1 << i);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (channel->t_late_period) {
|
||||
if (ch==CH_D0 && instru.tri_d0_as_5v_en==1) {
|
||||
if(channel->v_late) {
|
||||
chan_en[CH_D0] = 0;
|
||||
chan_en[8] = 0;
|
||||
} else {
|
||||
chan_en[CH_D0] = 0;
|
||||
chan_en[8] = 1;
|
||||
}
|
||||
} else if (ch==CH_D1 && instru.tri_d1_as_5v_en==1) {
|
||||
if(channel->v_late) {
|
||||
chan_en[CH_D1] = 0;
|
||||
chan_en[9] = 0;
|
||||
} else {
|
||||
chan_en[CH_D1] = 0;
|
||||
chan_en[9] = 1;
|
||||
}
|
||||
} else {
|
||||
chan_en[ch] = channel->v_late;
|
||||
}
|
||||
|
||||
if (channel->v_scan_rate >= channel->t_late) {
|
||||
channel->v_scan_rate -= channel->t_late; //To get right time
|
||||
channel->used = false;
|
||||
if (ch==CH_D0 && instru.tri_d0_as_5v_en==1) { //ending
|
||||
chan_en[CH_D0] = 0;
|
||||
chan_en[8] = 1;
|
||||
} else if (ch==CH_D1 && instru.tri_d1_as_5v_en==1) {
|
||||
chan_en[CH_D1] = 0;
|
||||
chan_en[9] = 1;
|
||||
} else {
|
||||
chan_en[ch] = 0;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void all_output_ctrl_mode_vsan(uint32_t delta_t)
|
||||
{
|
||||
struct mode_all_out_ctrl_ctx_t *mode = (struct mode_all_out_ctrl_ctx_t *)wm_get();
|
||||
struct ch_all_out_ctrl_ctx_t *ch;
|
||||
|
||||
for(int i=CH_PR0; i<=CH_PR1; i++) {
|
||||
ch = &mode->channel[i];
|
||||
__all_output_ctrl_mode_ch_vsan(ch, delta_t, i);
|
||||
}
|
||||
|
||||
if (mode->channel[CH_PR0].used == false &&
|
||||
mode->channel[CH_D0].used == false &&
|
||||
mode->channel[CH_A0].used == false &&
|
||||
mode->channel[CH_A2].used == false &&
|
||||
mode->channel[CH_A3].used == false &&
|
||||
mode->channel[CH_A1].used == false &&
|
||||
mode->channel[CH_D1].used == false &&
|
||||
mode->channel[CH_PR1].used == false)
|
||||
PeriodicEvent = false;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
int all_output_ctrl_mode_create(void)
|
||||
{
|
||||
struct mode_all_out_ctrl_ctx_t *p;
|
||||
void **wm = &workMode_p;
|
||||
|
||||
if (*wm)
|
||||
return -1;
|
||||
|
||||
p = malloc(sizeof(struct mode_all_out_ctrl_ctx_t));
|
||||
|
||||
if (!p)
|
||||
return -2;
|
||||
|
||||
struct ch_all_out_ctrl_ctx_t *ch;
|
||||
for (int i=CH_D0; i<=CH_D1; i++) {
|
||||
ch = &p->channel[i];
|
||||
ch->used = false;
|
||||
}
|
||||
|
||||
*wm = p;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void __all_output_ctrl_mode_channel_init(uint8_t *ins)
|
||||
{
|
||||
struct mode_all_out_ctrl_ctx_t *mode = (struct mode_all_out_ctrl_ctx_t *)wm_get();
|
||||
struct ch_all_out_ctrl_ctx_t *ch;
|
||||
uint8_t channel = ins[3];
|
||||
uint8_t para_sequence = ins[4];
|
||||
ch = &mode->channel[channel];
|
||||
|
||||
if (para_sequence == 1) {
|
||||
ch->used = (ins[5] & 1<<0);
|
||||
ch->v_early = (ins[5] & 1<<1) >> 1;
|
||||
ch->v_late = (ins[5] & 1<<2) >> 2;
|
||||
ch->v_mid = ins[6]; // |rsvd|v3|v2|v1|v0|
|
||||
ch->cycle = (uint16_t)ins[7] << 8 | (uint16_t)ins[8];
|
||||
ch->t_early = (uint32_t)ins[9] << 24 | (uint32_t)ins[10] << 16 | (uint32_t)ins[11] << 8 | (uint32_t)ins[12]; // 1ms->0.1ms
|
||||
ch->t_early *=10;
|
||||
ch->t_late = (uint32_t)ins[13] << 24 | (uint32_t)ins[14] << 16 | (uint32_t)ins[15] << 8 | (uint32_t)ins[16];
|
||||
ch->t_late *=10;
|
||||
|
||||
} else if (para_sequence == 2) {
|
||||
ch->t_mid[0] = (uint32_t)ins[5] << 24 | (uint32_t)ins[6] << 16 | (uint32_t)ins[7] << 8 | (uint32_t)ins[8];
|
||||
ch->t_mid[0] *= 10;
|
||||
ch->t_mid[1] = (uint32_t)ins[9] << 24 | (uint32_t)ins[10] << 16 | (uint32_t)ins[11] << 8 | (uint32_t)ins[12];
|
||||
ch->t_mid[1] *= 10;
|
||||
|
||||
} else if (para_sequence == 3) {
|
||||
ch->t_mid[2] = (uint32_t)ins[5] << 24 | (uint32_t)ins[6] << 16 | (uint32_t)ins[7] << 8 | (uint32_t)ins[8];
|
||||
ch->t_mid[2] *= 10;
|
||||
ch->t_mid[3] = (uint32_t)ins[9] << 24 | (uint32_t)ins[10] << 16 | (uint32_t)ins[11] << 8 | (uint32_t)ins[12];
|
||||
ch->t_mid[3] *= 10;
|
||||
ch->t_period = 0;
|
||||
for (int i=0; i<4; i++) {
|
||||
ch->t_period += ch->t_mid[i];
|
||||
ch->t_part[i] = ch->t_period;
|
||||
}
|
||||
|
||||
if (ch->used == true)
|
||||
ch->init = true;
|
||||
else
|
||||
ch->init = false;
|
||||
|
||||
ch->t_early_period = true;
|
||||
ch->t_mid_period = false;
|
||||
ch->t_late_period = false;
|
||||
|
||||
} else if (para_sequence == 4) {
|
||||
if (channel==CH_D0) {
|
||||
instru.tri_d0_as_5v_en = ins[5];
|
||||
} else if (channel==CH_D1) {
|
||||
instru.tri_d1_as_5v_en = ins[5];
|
||||
} else if (channel==CH_A0) {
|
||||
instru.Trig_CurCon[0] = (uint16_t)ins[5] << 8 | (uint16_t)ins[6]; //5000=20mA
|
||||
} else if (channel==CH_A1) {
|
||||
instru.Trig_CurCon[1] = (uint16_t)ins[5] << 8 | (uint16_t)ins[6];
|
||||
} else if (channel==CH_A2) {
|
||||
instru.Trig_CurCon[2] = (uint16_t)ins[5] << 8 | (uint16_t)ins[6];
|
||||
} else if (channel==CH_A3) {
|
||||
instru.Trig_CurCon[3] = (uint16_t)ins[5] << 8 | (uint16_t)ins[6];
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void handle_all_output_mode_instru(uint8_t *recv_instru, struct elite_instru_t *instruction)
|
||||
{
|
||||
uint8_t *ins = recv_instru;
|
||||
uint8_t ch = ins[3];
|
||||
|
||||
switch (ch) {
|
||||
case 0xFF:
|
||||
instru.elite_mode = MODE_ALL_OUTPUT_CTRL;
|
||||
all_output_ctrl_mode_create();
|
||||
break;
|
||||
|
||||
case CH_PR0:
|
||||
case CH_PR1:
|
||||
case CH_D0:
|
||||
case CH_D1:
|
||||
case CH_A0:
|
||||
case CH_A1:
|
||||
case CH_A2:
|
||||
case CH_A3:
|
||||
__all_output_ctrl_mode_channel_init(ins);
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
instruction->notify_rate = 5000;
|
||||
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
Target Device: CC2650, CC2640
|
||||
|
||||
******************************************************************************
|
||||
|
||||
|
||||
Copyright (c) 2010-2018, Texas Instruments Incorporated
|
||||
All rights reserved.
|
||||
|
||||
@@ -135,7 +135,6 @@ static simpleProfileCBs_t *simpleProfile_AppCBs = NULL;
|
||||
// Simple Profile Service attribute
|
||||
static CONST gattAttrType_t simpleProfileService = { ATT_BT_UUID_SIZE, simpleProfileServUUID };
|
||||
|
||||
|
||||
// Simple Profile Characteristic 1 Properties
|
||||
// static uint8 simpleProfileChar1Props = GATT_PROP_READ | GATT_PROP_WRITE;
|
||||
/*user insert*/
|
||||
@@ -144,13 +143,12 @@ static uint8 simpleProfileChar1Props = GATT_PROP_READ;
|
||||
// Characteristic 1 Value
|
||||
// static uint8 simpleProfileChar1 = 0;
|
||||
/*user insert*/
|
||||
#define SIMPLEPROFILE_CHAR1_LEN 20
|
||||
static uint8 simpleProfileChar1[SIMPLEPROFILE_CHAR1_LEN] = {0};
|
||||
|
||||
|
||||
// Simple Profile Characteristic 1 User Description
|
||||
static uint8 simpleProfileChar1UserDesp[17] = "Characteristic 1";
|
||||
|
||||
|
||||
// Simple Profile Characteristic 2 Properties
|
||||
static uint8 simpleProfileChar2Props = GATT_PROP_READ;
|
||||
|
||||
@@ -159,11 +157,9 @@ static uint8 simpleProfileChar2Props = GATT_PROP_READ;
|
||||
/*user insert*/
|
||||
static uint8 simpleProfileChar2[SIMPLEPROFILE_CHAR2_LEN] = {0};
|
||||
|
||||
|
||||
// Simple Profile Characteristic 2 User Description
|
||||
static uint8 simpleProfileChar2UserDesp[17] = "Characteristic 2";
|
||||
|
||||
|
||||
// Simple Profile Characteristic 3 Properties
|
||||
static uint8 simpleProfileChar3Props = GATT_PROP_WRITE;
|
||||
|
||||
@@ -172,11 +168,9 @@ static uint8 simpleProfileChar3Props = GATT_PROP_WRITE;
|
||||
/*user insert*/
|
||||
static uint8 simpleProfileChar3[SIMPLEPROFILE_CHAR3_LEN] = {0};
|
||||
|
||||
|
||||
// Simple Profile Characteristic 3 User Description
|
||||
static uint8 simpleProfileChar3UserDesp[17] = "Characteristic 3";
|
||||
|
||||
|
||||
// Simple Profile Characteristic 4 Properties
|
||||
static uint8 simpleProfileChar4Props = GATT_PROP_NOTIFY;
|
||||
|
||||
@@ -185,7 +179,6 @@ static uint8 simpleProfileChar4Props = GATT_PROP_NOTIFY;
|
||||
/*user insert*/
|
||||
static uint8 simpleProfileChar4[SIMPLEPROFILE_CHAR4_LEN] = {0};
|
||||
|
||||
|
||||
// Simple Profile Characteristic 4 Configuration Each client has its own
|
||||
// instantiation of the Client Characteristic Configuration. Reads of the
|
||||
// Client Characteristic Configuration only shows the configuration for
|
||||
@@ -195,7 +188,6 @@ static gattCharCfg_t *simpleProfileChar4Config;
|
||||
// Simple Profile Characteristic 4 User Description
|
||||
static uint8 simpleProfileChar4UserDesp[17] = "Characteristic 4";
|
||||
|
||||
|
||||
// Simple Profile Characteristic 5 Properties
|
||||
static uint8 simpleProfileChar5Props = GATT_PROP_READ;
|
||||
|
||||
@@ -230,17 +222,17 @@ static gattAttribute_t simpleProfileAttrTbl[SERVAPP_NUM_ATTR_SUPPORTED] =
|
||||
// Characteristic Value 1
|
||||
{
|
||||
{ ATT_BT_UUID_SIZE, simpleProfilechar1UUID },
|
||||
GATT_PERMIT_READ,
|
||||
0,
|
||||
simpleProfileChar1
|
||||
GATT_PERMIT_READ,
|
||||
0,
|
||||
simpleProfileChar1
|
||||
},
|
||||
|
||||
// Characteristic 1 User Description
|
||||
{
|
||||
{ ATT_BT_UUID_SIZE, charUserDescUUID },
|
||||
GATT_PERMIT_READ,
|
||||
0,
|
||||
simpleProfileChar1UserDesp
|
||||
GATT_PERMIT_READ,
|
||||
0,
|
||||
simpleProfileChar1UserDesp
|
||||
},
|
||||
|
||||
// Characteristic 2 Declaration
|
||||
@@ -254,112 +246,114 @@ static gattAttribute_t simpleProfileAttrTbl[SERVAPP_NUM_ATTR_SUPPORTED] =
|
||||
// Characteristic Value 2
|
||||
{
|
||||
{ ATT_BT_UUID_SIZE, simpleProfilechar2UUID },
|
||||
GATT_PERMIT_READ,
|
||||
0,
|
||||
simpleProfileChar2
|
||||
},
|
||||
GATT_PERMIT_READ,
|
||||
0,
|
||||
simpleProfileChar2
|
||||
},
|
||||
|
||||
// Characteristic 2 User Description
|
||||
{
|
||||
{ ATT_BT_UUID_SIZE, charUserDescUUID },
|
||||
GATT_PERMIT_READ,
|
||||
0,
|
||||
simpleProfileChar2UserDesp
|
||||
},
|
||||
|
||||
|
||||
// Characteristic 2 User Description
|
||||
{
|
||||
{ ATT_BT_UUID_SIZE, charUserDescUUID },
|
||||
GATT_PERMIT_READ,
|
||||
0,
|
||||
simpleProfileChar2UserDesp
|
||||
},
|
||||
|
||||
// Characteristic 3 Declaration
|
||||
{
|
||||
{ ATT_BT_UUID_SIZE, characterUUID },
|
||||
GATT_PERMIT_READ,
|
||||
0,
|
||||
{ ATT_BT_UUID_SIZE, characterUUID },
|
||||
GATT_PERMIT_READ,
|
||||
0,
|
||||
&simpleProfileChar3Props
|
||||
},
|
||||
|
||||
// Characteristic Value 3
|
||||
{
|
||||
{ ATT_BT_UUID_SIZE, simpleProfilechar3UUID },
|
||||
GATT_PERMIT_WRITE,
|
||||
0,
|
||||
simpleProfileChar3
|
||||
},
|
||||
// Characteristic Value 3
|
||||
{
|
||||
{ ATT_BT_UUID_SIZE, simpleProfilechar3UUID },
|
||||
GATT_PERMIT_WRITE,
|
||||
0,
|
||||
simpleProfileChar3
|
||||
},
|
||||
|
||||
// Characteristic 3 User Description
|
||||
{
|
||||
{ ATT_BT_UUID_SIZE, charUserDescUUID },
|
||||
GATT_PERMIT_READ,
|
||||
0,
|
||||
simpleProfileChar3UserDesp
|
||||
},
|
||||
// Characteristic 3 User Description
|
||||
{
|
||||
{ ATT_BT_UUID_SIZE, charUserDescUUID },
|
||||
GATT_PERMIT_READ,
|
||||
0,
|
||||
simpleProfileChar3UserDesp
|
||||
},
|
||||
|
||||
// Characteristic 4 Declaration
|
||||
{
|
||||
{ ATT_BT_UUID_SIZE, characterUUID },
|
||||
GATT_PERMIT_READ,
|
||||
{ ATT_BT_UUID_SIZE, characterUUID },
|
||||
GATT_PERMIT_READ,
|
||||
0,
|
||||
&simpleProfileChar4Props
|
||||
},
|
||||
|
||||
// Characteristic Value 4
|
||||
{
|
||||
{ ATT_BT_UUID_SIZE, simpleProfilechar4UUID },
|
||||
0,
|
||||
0,
|
||||
simpleProfileChar4
|
||||
},
|
||||
// Characteristic Value 4
|
||||
{
|
||||
{ ATT_BT_UUID_SIZE, simpleProfilechar4UUID },
|
||||
0,
|
||||
0,
|
||||
simpleProfileChar4
|
||||
},
|
||||
|
||||
// Characteristic 4 configuration
|
||||
{
|
||||
{ ATT_BT_UUID_SIZE, clientCharCfgUUID },
|
||||
GATT_PERMIT_READ | GATT_PERMIT_WRITE,
|
||||
0,
|
||||
(uint8 *)&simpleProfileChar4Config
|
||||
},
|
||||
// Characteristic 4 configuration
|
||||
{
|
||||
{ ATT_BT_UUID_SIZE, clientCharCfgUUID },
|
||||
GATT_PERMIT_READ | GATT_PERMIT_WRITE,
|
||||
0,
|
||||
(uint8 *)&simpleProfileChar4Config
|
||||
},
|
||||
|
||||
// Characteristic 4 User Description
|
||||
{
|
||||
{ ATT_BT_UUID_SIZE, charUserDescUUID },
|
||||
GATT_PERMIT_READ,
|
||||
0,
|
||||
simpleProfileChar4UserDesp
|
||||
},
|
||||
// Characteristic 4 User Description
|
||||
{
|
||||
{ ATT_BT_UUID_SIZE, charUserDescUUID },
|
||||
GATT_PERMIT_READ,
|
||||
0,
|
||||
simpleProfileChar4UserDesp
|
||||
},
|
||||
|
||||
// Characteristic 5 Declaration
|
||||
{
|
||||
{ ATT_BT_UUID_SIZE, characterUUID },
|
||||
GATT_PERMIT_READ,
|
||||
0,
|
||||
{ ATT_BT_UUID_SIZE, characterUUID },
|
||||
GATT_PERMIT_READ,
|
||||
0,
|
||||
&simpleProfileChar5Props
|
||||
},
|
||||
|
||||
// Characteristic Value 5
|
||||
{
|
||||
{ ATT_BT_UUID_SIZE, simpleProfilechar5UUID },
|
||||
GATT_PERMIT_AUTHEN_READ,
|
||||
0,
|
||||
simpleProfileChar5
|
||||
},
|
||||
// Characteristic Value 5
|
||||
{
|
||||
{ ATT_BT_UUID_SIZE, simpleProfilechar5UUID },
|
||||
GATT_PERMIT_AUTHEN_READ,
|
||||
0,
|
||||
simpleProfileChar5
|
||||
},
|
||||
|
||||
// Characteristic 5 User Description
|
||||
{
|
||||
{ ATT_BT_UUID_SIZE, charUserDescUUID },
|
||||
GATT_PERMIT_READ,
|
||||
0,
|
||||
simpleProfileChar5UserDesp
|
||||
},
|
||||
// Characteristic 5 User Description
|
||||
{
|
||||
{ ATT_BT_UUID_SIZE, charUserDescUUID },
|
||||
GATT_PERMIT_READ,
|
||||
0,
|
||||
simpleProfileChar5UserDesp
|
||||
},
|
||||
};
|
||||
|
||||
/*********************************************************************
|
||||
* LOCAL FUNCTIONS
|
||||
*/
|
||||
static bStatus_t simpleProfile_ReadAttrCB(uint16_t connHandle,
|
||||
gattAttribute_t *pAttr,
|
||||
uint8_t *pValue, uint16_t *pLen,
|
||||
uint16_t offset, uint16_t maxLen,
|
||||
uint8_t method);
|
||||
gattAttribute_t *pAttr,
|
||||
uint8_t *pValue, uint16_t *pLen,
|
||||
uint16_t offset, uint16_t maxLen,
|
||||
uint8_t method);
|
||||
static bStatus_t simpleProfile_WriteAttrCB(uint16_t connHandle,
|
||||
gattAttribute_t *pAttr,
|
||||
uint8_t *pValue, uint16_t len,
|
||||
uint16_t offset, uint8_t method);
|
||||
gattAttribute_t *pAttr,
|
||||
uint8_t *pValue, uint16_t len,
|
||||
uint16_t offset, uint8_t method);
|
||||
|
||||
/*********************************************************************
|
||||
* PROFILE CALLBACKS
|
||||
@@ -401,7 +395,7 @@ bStatus_t SimpleProfile_AddService( uint32 services )
|
||||
|
||||
// Allocate Client Characteristic Configuration table
|
||||
simpleProfileChar4Config = (gattCharCfg_t *)ICall_malloc( sizeof(gattCharCfg_t) *
|
||||
linkDBNumConns );
|
||||
linkDBNumConns );
|
||||
if ( simpleProfileChar4Config == NULL )
|
||||
{
|
||||
return ( bleMemAllocError );
|
||||
@@ -414,9 +408,9 @@ bStatus_t SimpleProfile_AddService( uint32 services )
|
||||
{
|
||||
// Register GATT attribute list and CBs with GATT Server App
|
||||
status = GATTServApp_RegisterService( simpleProfileAttrTbl,
|
||||
GATT_NUM_ATTRS( simpleProfileAttrTbl ),
|
||||
GATT_MAX_ENCRYPT_KEY_SIZE,
|
||||
&simpleProfileCBs );
|
||||
GATT_NUM_ATTRS( simpleProfileAttrTbl ),
|
||||
GATT_MAX_ENCRYPT_KEY_SIZE,
|
||||
&simpleProfileCBs );
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -474,7 +468,7 @@ bStatus_t SimpleProfile_SetParameter( uint8 param, uint8 len, void *value )
|
||||
{
|
||||
memcpy(simpleProfileChar1, value, len);
|
||||
// simpleProfileChar1 = *((uint8*)value);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = bleInvalidRange;
|
||||
@@ -488,7 +482,7 @@ bStatus_t SimpleProfile_SetParameter( uint8 param, uint8 len, void *value )
|
||||
// simpleProfileChar2 = *((uint8*)value);
|
||||
}
|
||||
else
|
||||
{
|
||||
{
|
||||
ret = bleInvalidRange;
|
||||
}
|
||||
break;
|
||||
@@ -497,8 +491,7 @@ bStatus_t SimpleProfile_SetParameter( uint8 param, uint8 len, void *value )
|
||||
if (len <= SIMPLEPROFILE_CHAR3_LEN)
|
||||
{
|
||||
memcpy(simpleProfileChar3, value, len);
|
||||
// simpleProfileChar3 = *((uint8*)value);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = bleInvalidRange;
|
||||
@@ -509,12 +502,9 @@ bStatus_t SimpleProfile_SetParameter( uint8 param, uint8 len, void *value )
|
||||
if (len <= SIMPLEPROFILE_CHAR4_LEN)
|
||||
{
|
||||
memcpy(simpleProfileChar4, value, len);
|
||||
// simpleProfileChar4 = *((uint8*)value);
|
||||
|
||||
// See if Notification has been enabled
|
||||
GATTServApp_ProcessCharCfg( simpleProfileChar4Config, simpleProfileChar4, FALSE,
|
||||
simpleProfileAttrTbl, GATT_NUM_ATTRS( simpleProfileAttrTbl ),
|
||||
INVALID_TASK_ID, simpleProfile_ReadAttrCB );
|
||||
GATTServApp_ProcessCharCfg(simpleProfileChar4Config, simpleProfileChar4, FALSE, simpleProfileAttrTbl, GATT_NUM_ATTRS(simpleProfileAttrTbl), INVALID_TASK_ID, simpleProfile_ReadAttrCB);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -523,9 +513,8 @@ bStatus_t SimpleProfile_SetParameter( uint8 param, uint8 len, void *value )
|
||||
break;
|
||||
|
||||
case SIMPLEPROFILE_CHAR5:
|
||||
if ( len == SIMPLEPROFILE_CHAR5_LEN )
|
||||
{
|
||||
VOID memcpy( simpleProfileChar5, value, SIMPLEPROFILE_CHAR5_LEN );
|
||||
if (len == SIMPLEPROFILE_CHAR5_LEN) {
|
||||
VOID memcpy(simpleProfileChar5, value, SIMPLEPROFILE_CHAR5_LEN);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -554,41 +543,37 @@ bStatus_t SimpleProfile_SetParameter( uint8 param, uint8 len, void *value )
|
||||
*
|
||||
* @return bStatus_t
|
||||
*/
|
||||
bStatus_t SimpleProfile_GetParameter( uint8 param, void *value )
|
||||
{
|
||||
bStatus_t ret = SUCCESS;
|
||||
switch ( param )
|
||||
{
|
||||
bStatus_t SimpleProfile_GetParameter(uint8 param, void *value) {
|
||||
bStatus_t ret = SUCCESS;
|
||||
switch (param) {
|
||||
case SIMPLEPROFILE_CHAR1:
|
||||
memcpy(value, simpleProfileChar1, SIMPLEPROFILE_CHAR1_LEN);
|
||||
// *((uint8*)value) = simpleProfileChar1;
|
||||
break;
|
||||
memcpy(value, simpleProfileChar1, SIMPLEPROFILE_CHAR1_LEN);
|
||||
// *((uint8*)value) = simpleProfileChar1;
|
||||
break;
|
||||
|
||||
case SIMPLEPROFILE_CHAR2:
|
||||
memcpy(value, simpleProfileChar2, SIMPLEPROFILE_CHAR2_LEN);
|
||||
// *((uint8*)value) = simpleProfileChar2;
|
||||
break;
|
||||
memcpy(value, simpleProfileChar2, SIMPLEPROFILE_CHAR2_LEN);
|
||||
// *((uint8*)value) = simpleProfileChar2;
|
||||
break;
|
||||
|
||||
case SIMPLEPROFILE_CHAR3:
|
||||
memcpy(value, simpleProfileChar3, SIMPLEPROFILE_CHAR3_LEN);
|
||||
// *((uint8*)value) = simpleProfileChar3;
|
||||
break;
|
||||
memcpy(value, simpleProfileChar3, SIMPLEPROFILE_CHAR3_LEN);
|
||||
break;
|
||||
|
||||
case SIMPLEPROFILE_CHAR4:
|
||||
memcpy(value, simpleProfileChar4, SIMPLEPROFILE_CHAR4_LEN);
|
||||
// *((uint8*)value) = simpleProfileChar4;
|
||||
break;
|
||||
memcpy(value, simpleProfileChar4, SIMPLEPROFILE_CHAR4_LEN);
|
||||
break;
|
||||
|
||||
case SIMPLEPROFILE_CHAR5:
|
||||
VOID memcpy( value, simpleProfileChar5, SIMPLEPROFILE_CHAR5_LEN );
|
||||
break;
|
||||
VOID memcpy(value, simpleProfileChar5, SIMPLEPROFILE_CHAR5_LEN);
|
||||
break;
|
||||
|
||||
default:
|
||||
ret = INVALIDPARAMETER;
|
||||
break;
|
||||
}
|
||||
ret = INVALIDPARAMETER;
|
||||
break;
|
||||
}
|
||||
|
||||
return ( ret );
|
||||
return (ret);
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
@@ -606,69 +591,62 @@ bStatus_t SimpleProfile_GetParameter( uint8 param, void *value )
|
||||
*
|
||||
* @return SUCCESS, blePending or Failure
|
||||
*/
|
||||
static bStatus_t simpleProfile_ReadAttrCB(uint16_t connHandle,
|
||||
gattAttribute_t *pAttr,
|
||||
uint8_t *pValue, uint16_t *pLen,
|
||||
uint16_t offset, uint16_t maxLen,
|
||||
uint8_t method)
|
||||
{
|
||||
bStatus_t status = SUCCESS;
|
||||
static bStatus_t simpleProfile_ReadAttrCB(uint16_t connHandle, gattAttribute_t *pAttr, uint8_t *pValue, uint16_t *pLen, uint16_t offset, uint16_t maxLen, uint8_t method) {
|
||||
bStatus_t status = SUCCESS;
|
||||
|
||||
// Make sure it's not a blob operation (no attributes in the profile are long)
|
||||
if ( offset > 0 )
|
||||
{
|
||||
return ( ATT_ERR_ATTR_NOT_LONG );
|
||||
}
|
||||
|
||||
if ( pAttr->type.len == ATT_BT_UUID_SIZE )
|
||||
{
|
||||
// 16-bit UUID
|
||||
uint16 uuid = BUILD_UINT16( pAttr->type.uuid[0], pAttr->type.uuid[1]);
|
||||
switch ( uuid )
|
||||
{
|
||||
// No need for "GATT_SERVICE_UUID" or "GATT_CLIENT_CHAR_CFG_UUID" cases;
|
||||
// gattserverapp handles those reads
|
||||
|
||||
// characteristics 1 and 2 have read permissions
|
||||
// characteritisc 3 does not have read permissions; therefore it is not
|
||||
// included here
|
||||
// characteristic 4 does not have read permissions, but because it
|
||||
// can be sent as a notification, it is included here
|
||||
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;
|
||||
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 );
|
||||
break;
|
||||
|
||||
case SIMPLEPROFILE_CHAR5_UUID:
|
||||
*pLen = SIMPLEPROFILE_CHAR5_LEN;
|
||||
VOID memcpy( pValue, pAttr->pValue, SIMPLEPROFILE_CHAR5_LEN );
|
||||
break;
|
||||
|
||||
default:
|
||||
// Should never get here! (characteristics 3 and 4 do not have read permissions)
|
||||
*pLen = 0;
|
||||
status = ATT_ERR_ATTR_NOT_FOUND;
|
||||
break;
|
||||
// Make sure it's not a blob operation (no attributes in the profile are long)
|
||||
if (offset > 0) {
|
||||
return (ATT_ERR_ATTR_NOT_LONG);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// 128-bit UUID
|
||||
*pLen = 0;
|
||||
status = ATT_ERR_INVALID_HANDLE;
|
||||
}
|
||||
|
||||
return ( status );
|
||||
if (pAttr->type.len == ATT_BT_UUID_SIZE) {
|
||||
// 16-bit UUID
|
||||
uint16 uuid = BUILD_UINT16(pAttr->type.uuid[0], pAttr->type.uuid[1]);
|
||||
switch (uuid) {
|
||||
// No need for "GATT_SERVICE_UUID" or "GATT_CLIENT_CHAR_CFG_UUID" cases;
|
||||
// gattserverapp handles those reads
|
||||
|
||||
// characteristics 1 and 2 have read permissions
|
||||
// characteritisc 3 does not have read permissions; therefore it is not
|
||||
// included here
|
||||
// characteristic 4 does not have read permissions, but because it
|
||||
// can be sent as a notification, it is included here
|
||||
case SIMPLEPROFILE_CHAR1_UUID:
|
||||
*pLen = SIMPLEPROFILE_CHAR1_LEN;
|
||||
VOID memcpy(pValue, pAttr->pValue, SIMPLEPROFILE_CHAR1_LEN);
|
||||
break;
|
||||
|
||||
case SIMPLEPROFILE_CHAR2_UUID:
|
||||
// *pLen = 1;
|
||||
// pValue[0] = *pAttr->pValue;
|
||||
|
||||
*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);
|
||||
break;
|
||||
// case SIMPLEPROFILE_CHAR5_UUID:
|
||||
|
||||
// *pLen = SIMPLEPROFILE_CHAR5_LEN;
|
||||
// VOID memcpy( pValue, pAttr->pValue, SIMPLEPROFILE_CHAR5_LEN );
|
||||
// break;
|
||||
|
||||
default:
|
||||
// Should never get here! (characteristics 3 and 4 do not have read permissions)
|
||||
*pLen = 0;
|
||||
status = ATT_ERR_ATTR_NOT_FOUND;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
// 128-bit UUID
|
||||
*pLen = 0;
|
||||
status = ATT_ERR_INVALID_HANDLE;
|
||||
}
|
||||
|
||||
return (status);
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
@@ -685,109 +663,83 @@ static bStatus_t simpleProfile_ReadAttrCB(uint16_t connHandle,
|
||||
*
|
||||
* @return SUCCESS, blePending or Failure
|
||||
*/
|
||||
static bStatus_t simpleProfile_WriteAttrCB(uint16_t connHandle,
|
||||
gattAttribute_t *pAttr,
|
||||
uint8_t *pValue, uint16_t len,
|
||||
uint16_t offset, uint8_t method)
|
||||
{
|
||||
bStatus_t status = SUCCESS;
|
||||
uint8 notifyApp = 0xFF;
|
||||
static bStatus_t simpleProfile_WriteAttrCB(uint16_t connHandle, gattAttribute_t *pAttr, uint8_t *pValue, uint16_t len, uint16_t offset, uint8_t method) {
|
||||
bStatus_t status = SUCCESS;
|
||||
uint8 notifyApp = 0xFF;
|
||||
|
||||
if ( pAttr->type.len == ATT_BT_UUID_SIZE )
|
||||
{
|
||||
// 16-bit UUID
|
||||
uint16 uuid = BUILD_UINT16( pAttr->type.uuid[0], pAttr->type.uuid[1]);
|
||||
switch ( uuid )
|
||||
{
|
||||
// case SIMPLEPROFILE_CHAR1_UUID:
|
||||
case SIMPLEPROFILE_CHAR3_UUID:
|
||||
//Validate the value
|
||||
// Make sure it's not a blob oper
|
||||
if ( offset == 0 )
|
||||
{
|
||||
if ( len > SIMPLEPROFILE_CHAR3_LEN )
|
||||
{
|
||||
status = ATT_ERR_INVALID_VALUE_SIZE;
|
||||
}
|
||||
if (pAttr->type.len == ATT_BT_UUID_SIZE) {
|
||||
// 16-bit UUID
|
||||
uint16 uuid = BUILD_UINT16(pAttr->type.uuid[0], pAttr->type.uuid[1]);
|
||||
switch (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;
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
*/
|
||||
case SIMPLEPROFILE_CHAR3_UUID:
|
||||
if (offset == 0) {
|
||||
if (len > SIMPLEPROFILE_CHAR3_LEN) {
|
||||
status = ATT_ERR_INVALID_VALUE_SIZE;
|
||||
}
|
||||
} else {
|
||||
status = ATT_ERR_ATTR_NOT_LONG;
|
||||
}
|
||||
|
||||
// Write the value
|
||||
if (status == SUCCESS) {
|
||||
// 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);
|
||||
|
||||
if (pAttr->pValue == simpleProfileChar3) {
|
||||
notifyApp = SIMPLEPROFILE_CHAR3;
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
case GATT_CLIENT_CHAR_CFG_UUID:
|
||||
status = GATTServApp_ProcessCCCWriteReq(connHandle, pAttr, pValue, len, offset, GATT_CLIENT_CFG_NOTIFY);
|
||||
break;
|
||||
default:
|
||||
// Should never get here! (characteristics 2 and 4 do not have write permissions)
|
||||
status = ATT_ERR_ATTR_NOT_FOUND;
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
status = ATT_ERR_ATTR_NOT_LONG;
|
||||
}
|
||||
|
||||
//Write the value
|
||||
if ( status == SUCCESS )
|
||||
{
|
||||
// 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);
|
||||
|
||||
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 );
|
||||
break;
|
||||
|
||||
default:
|
||||
// Should never get here! (characteristics 2 and 4 do not have write permissions)
|
||||
status = ATT_ERR_ATTR_NOT_FOUND;
|
||||
break;
|
||||
} else {
|
||||
// 128-bit UUID
|
||||
status = ATT_ERR_INVALID_HANDLE;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// 128-bit UUID
|
||||
status = ATT_ERR_INVALID_HANDLE;
|
||||
}
|
||||
|
||||
// If a characteristic value changed then callback function to notify application of change
|
||||
if ( (notifyApp != 0xFF ) && simpleProfile_AppCBs && simpleProfile_AppCBs->pfnSimpleProfileChange )
|
||||
{
|
||||
simpleProfile_AppCBs->pfnSimpleProfileChange( notifyApp );
|
||||
}
|
||||
// If a characteristic value changed then callback function to notify application of change
|
||||
if ((notifyApp != 0xFF) && simpleProfile_AppCBs && simpleProfile_AppCBs->pfnSimpleProfileChange) {
|
||||
simpleProfile_AppCBs->pfnSimpleProfileChange(notifyApp);
|
||||
}
|
||||
|
||||
return ( status );
|
||||
return (status);
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
|
||||
@@ -83,11 +83,10 @@ extern "C"
|
||||
|
||||
// Length of Characteristic 5 in bytes
|
||||
#define SIMPLEPROFILE_CHAR5_LEN 5
|
||||
/*user insert*/
|
||||
#define SIMPLEPROFILE_CHAR4_LEN 40
|
||||
#define SIMPLEPROFILE_CHAR3_LEN 20
|
||||
#define SIMPLEPROFILE_CHAR2_LEN 20
|
||||
#define SIMPLEPROFILE_CHAR1_LEN 20
|
||||
|
||||
/*********************************************************************
|
||||
* TYPEDEFS
|
||||
*/
|
||||
|
||||