Compare commits

...

41 Commits

Author SHA1 Message Date
Roy 408d9f35df Docs: update gitignore 2023-06-06 17:29:37 +08:00
Roy dd0e591b8d Feat: MCP23008 tool 2023-06-06 16:19:48 +08:00
ROY cdf50c6c48 [clean] 2023-03-16 16:02:26 +08:00
ROY 47f4fd49e5 [clean] 2023-03-16 15:41:54 +08:00
ROY 9e623f46da [clean] 2023-03-16 15:39:41 +08:00
ROY 42d803e739 [clean] 2023-03-16 15:31:56 +08:00
ROY e4bef28ead [clean] 2023-03-16 15:17:18 +08:00
ROY ae61ec610f [clean] 2023-03-16 15:09:45 +08:00
ROY f3a8943c1e [clean] 2023-03-16 15:02:55 +08:00
ROY 3990c4db8f [clean] 2023-03-16 14:57:37 +08:00
ROY ead65c3c94 [clean] 2023-03-16 14:51:06 +08:00
ROY b41e757e44 [clean] 2023-03-16 14:44:57 +08:00
ROY bfcf716b94 [clean] 2023-03-16 14:35:27 +08:00
ROY ba1aeb4670 [clean] 2023-03-16 14:29:54 +08:00
ROY 6541fd1386 [update] update timer 2023-03-16 13:40:35 +08:00
ROY b95ebc697e [update] update gpio 2023-03-16 12:43:01 +08:00
ROY dbb85e508a [update] update gpio 2023-03-15 18:03:03 +08:00
ROY 39dd62b0a0 [update] update gpio code 2023-03-15 16:45:21 +08:00
ROY 2a24c65ad6 [update] update i2c code 2023-03-15 16:39:02 +08:00
ROY 2908c595d1 [update] update main.c code 2023-03-15 10:51:35 +08:00
ROY f9aa353292 [update] edit code 2023-03-15 10:48:08 +08:00
ROY df0f87c281 [update] fix MCP23008 2023-03-15 10:46:11 +08:00
ROY 82ca5435f5 [update] update spi0/1_write 2023-03-15 09:44:29 +08:00
ROY 18c25c1e62 [update] update ADGS1412 library 2023-03-08 18:04:18 +08:00
ROY ce47324003 [update] define header file 2023-03-08 16:56:02 +08:00
ROY 390822f893 [update] update MAX5136 library 2023-03-08 15:07:15 +08:00
ROY fa06908a08 [update] update APA102 library 2023-03-08 14:57:20 +08:00
ROY bb425dd5bd [update] update MCP23008 library 2023-03-08 14:54:31 +08:00
ROY 607702ae23 [update] update MCP23008 library 2023-03-08 11:11:19 +08:00
ROY 09c3a67657 [update] update i2c function 2023-03-06 14:34:04 +08:00
ROY 05e8dc5982 [update] update led function 2023-03-03 15:01:06 +08:00
ROY 62d28c4054 [update] update spi function 2023-03-03 14:46:23 +08:00
ROY 84339ea967 [update] clean up pin define and gatt function 2023-03-03 11:07:28 +08:00
ROY b5da45124d [update] clean up pin define and gatt function 2023-03-03 11:07:09 +08:00
ROY 8d9e4eab63 [update] update gatt file 2023-03-02 14:52:21 +08:00
ROY 41d20603d1 [update] update gatt file 2023-03-02 13:35:36 +08:00
ROY 10a9a617ab [update] update device name 2023-02-14 14:21:18 +08:00
ROY 7fb3bd976f [update] fix led status 2023-02-14 14:17:25 +08:00
ROY d2a3a9a712 [update] spi 10M & update boot process 2023-01-30 17:33:03 +08:00
ROY ee75ad8341 [update] note spi 2023-01-30 17:31:21 +08:00
ROY 552569d985 [update] note mcp23008 reg_name 2023-01-17 10:16:04 +08:00
31 changed files with 9197 additions and 9155 deletions
+3
View File
@@ -1 +1,4 @@
simplelink/ble_sdk_2_02_02_25/examples/
simplelink/ble_sdk_2_02_02_25/src/common/cc26xx/ccs/
simplelink/ble_sdk_2_02_02_25/src/components/npi/src/
.vscode
@@ -50,7 +50,7 @@ extern "C" {
* ==========================================================================*/
#include <ti/drivers/PIN.h>
#include <driverlib/ioc.h>
#include "boards_config/elite_pin_conf.h"
#include "application_config/application_config.h"
/** ============================================================================
* Externs
@@ -146,12 +146,6 @@ 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
@@ -166,6 +160,27 @@ 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
#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,5 +1,5 @@
#ifndef ADGS1412_H
#define ADGS1412_H
#ifndef ADGS1412X2_H
#define ADGS1412X2_H
#ifdef __cplusplus
extern "C" {
@@ -1,4 +1,6 @@
#include "hardware/ADGS1412.h"
#include "application_config/application_config.h"
#include "HAL/cc2650_driver/spi_ctrl.h"
#include "HAL/ADGS1412x9.h"
static const uint8_t SPI_DAISY_CHAIN_COMMAND[2] = {0x25, 0x00};
@@ -9,8 +11,7 @@ static int __switch_transfer(struct switch_series_data_t *sd)
spi1_open(SPI_CLK_4M, POL0, PHA0);
pin_set(E_PIN_SWCSBB, 0);
#define WRITE_TO_SWITCH(_d, _l) spi1_write(NULL, (uint8_t *)(_d), (_l))
WRITE_TO_SWITCH(sd, 8);
spi1_write(NULL, (uint8_t *)(sd), 8);
pin_set(E_PIN_SWCSBB, 1);
return 0;
@@ -21,7 +22,6 @@ static int __switch_daisy_chain_mode() {
spi1_close();
spi1_open(SPI_CLK_4M, POL0, PHA0);
pin_set(E_PIN_SWCSBB, 0);
spi1_write(NULL, SPI_DAISY_CHAIN_COMMAND, 2);
pin_set(E_PIN_SWCSBB, 1);
@@ -0,0 +1,63 @@
#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,5 +1,3 @@
/* .h */
/*
* APA-102-2020-256-8A-20190612: Series data structure
* +-------------------+------------------------- ... -+-----------------+
@@ -14,74 +12,10 @@
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*/
#ifdef DEF_LED_TANDEN_N
#define LED_TANDEM_N DEF_LED_TANDEN_N
#else
#define LED_TANDEM_N 12
#endif
#include "application_config/application_config.h"
#include "HAL/cc2650_driver/spi_ctrl.h"
#include "HAL/APA102_2020_256_8x4.h"
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_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);
/* .c */
#define LED_FRME_FILL_RSVD(_f) (_f)->rsvd = 0x07 // 0x11100000 || bright
#define LED_SERIES_D_START 0x00000000
#define LED_SERIES_D_END 0xFFFFFFFF
@@ -181,8 +115,7 @@ static int __led_color_set(enum led_series_nb_e led_nb, struct led_frame_t *led_
__led_complete(sd);
#define WRITE_TO_HW(_d, _l) spi0_write(NULL, (void *)(_d), (_l))
WRITE_TO_HW(sd, sizeof(struct led_series_data_t));
spi0_write(NULL, (void *)(sd), sizeof(struct led_series_data_t));
return 0;
}
@@ -1,18 +1,14 @@
#ifndef DAC_MAX5136_H
#define DAC_MAX5136_H
#ifndef MAX5136X2_H
#define MAX5136X2_H
#define REVERT_2_BYTE(_b) ((_b) >> 8 | (((_b) & 0xFF) << 8))
#ifdef __cplusplus
extern "C" {
#endif
#define REVERT_2_BYTE(_b) ((_b) >> 8 | (((_b) & 0xFF) << 8))
#define MAX5136_NUM_MAX 2
#define SIZEOFDAC_SPI MAX5136_NUM_MAX*3
// #include "driver/spi_ctrl.h"
#define CTRL_B_LDAC 0x01
#define CTRL_B_CLR 0x02
@@ -62,4 +58,4 @@ int dac_enable_single_output(uint8_t dac0_enable, uint8_t dac1_enable, uint16_t
#ifdef __cplusplus
}
#endif
#endif //DAC_MAX5136_H
#endif
@@ -1,5 +1,20 @@
#include "hardware/DAC_MAX5136.h"
/*
* MAX5136
* CLR: Software clear.
* 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* |0 0 0 0 0 0 1 0|x x x x x x x x|x x x x x x x x|
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*
* Write-through: Write to selected input and DAC registers, DAC outputs updated(writethrough).
* 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3
* +-+-+-+-+--+--+--+--+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* |0 0 1 1 D3 D2 D1 D0| DAC data |
* +-+-+-+-+--+--+--+--+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*/
#include "application_config/application_config.h"
#include "HAL/cc2650_driver/spi_ctrl.h"
#include "HAL/MAX5136x2.h"
struct dac_series_data_t {
uint8_t control_bits;
@@ -12,16 +27,11 @@ static struct dac_series_data_t dac_series_data_g[MAX5136_NUM_MAX] = {0};
static int __dac_transfer(struct dac_series_data_t *sd)
{
spi1_close();
spi1_open(SPI_CLK_4M, POL1, PHA0);
pin_set(E_PIN_DACCS, 0);
#define WRITE_TO_DAC(_d, _l) spi1_write(NULL, (uint8_t *)(_d), (_l))
WRITE_TO_DAC(sd, SIZEOFDAC_SPI);
spi1_write(NULL, (uint8_t *)(sd), SIZEOFDAC_SPI);
pin_set(E_PIN_DACCS, 1);
return 0;
}
@@ -0,0 +1,75 @@
#ifndef MCP23008X2_H
#define MCP23008X2_H
#ifdef __cplusplus
extern "C" {
#endif
//i2c addr
/************************************************************************************************
* .h
************************************************************************************************/
#define GET_INPUT_SW_SEN() ((chip_MCP23008_rd_reg_stat(MCP23008_PB, MCP23008_REG_GPIO) & 0x40) >> 6)
#define PUSH_KEY (GET_INPUT_SW_SEN() == 0)
#define SET_VLOGIC_EN_GPIO(_v) (chip_MCP23008_set(MCP23008_PB, MCP23008_REG_GPIO, MCP23008_P4, _v))
#define SET_VLOGIC_EN_IODIR(_v) (chip_MCP23008_set(MCP23008_PB, MCP23008_REG_IODIR, MCP23008_P4, _v))
#define SET_SW_EN_GPIO(_v) (chip_MCP23008_set(MCP23008_PB, MCP23008_REG_GPIO, MCP23008_P5, _v))
enum mcp23008_module_e {
MCP23008_PA = 0,
MCP23008_PB,
MCP23008_MODULE_MAX,
};
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,
};
enum mcp23008_gpio_e {
MCP23008_P0 = 0,
MCP23008_P1,
MCP23008_P2,
MCP23008_P3,
MCP23008_P4,
MCP23008_P5,
MCP23008_P6,
MCP23008_P7,
MCP23008_PIN_ALL,
};
struct mcp23008_reg_name_t {
uint8_t iodir;
uint8_t gpio;
};
struct mcp23008_set_para_t {
enum mcp23008_module_e chip_module;
enum mcp23008_reg_name_e reg_addr;
uint8_t val;
};
int chip_MCP23008_set(enum mcp23008_module_e i2c_module, enum mcp23008_reg_name_e reg_address, enum mcp23008_gpio_e wt_bit, uint8_t value);
uint8_t chip_MCP23008_rd_reg_stat(enum mcp23008_module_e i2c_module, enum mcp23008_reg_name_e reg_address);
#ifdef __cplusplus
}
#endif
#endif
@@ -1,4 +1,55 @@
#include "hardware/MCP23008.h"
/*
* MCP23008: Series data structure
* I2C
* -Write:
* +---------------------+------------------------+-------------+
* | Device Opcode(1B) | Register Address(1B) | Value(1B) |
* +---------------------+------------------------+-------------+
* / \
* / Device Opcode(1B)\
* / \
* 0 1 2 3 4 5 6 7
* +-+-+-+-+--+--+--+---+
* | 0100 |A2 A1 A0 R/W|
* +-+-+-+-+--+--+--+---+
* ps.CC2650 I2C parameter:I2C_addrtxtxlenrxlen,
* I2C_addr = 0b 0 1 0 0 A2 A1 A0
* tx = Register Address + Value
* txlen=2
* rxlen=1
*
*
* -Read:
* +---------------------+------------------------+
* | Device Opcode(1B) | Register Address(1B) |
* +---------------------+------------------------+
* / \
* / Device Opcode(1B)\
* / \
* 0 1 2 3 4 5 6 7
* +-+-+-+-+--+--+--+---+
* | 0100 |A2 A1 A0 R/W|
* +-+-+-+-+--+--+--+---+
* ps.CC2650 I2C parameter:I2C_addrtxtxlenrxlen,
* I2C_addr = 0b 0 1 0 0 A2 A1 A0
* tx = Register Address
* txlen=1
* rxlen=1
*
*/
#include "HAL/cc2650_driver/i2c_ctrl.h"
#include "HAL/MCP23008x2.h"
#define MCP23008_WT_BIT 0
#define MCP23008_RD_BIT 1
static uint8_t module_addr_g[MCP23008_MODULE_MAX] = {
0x4C, // MCP23008_PA
0x46, // MCP23008_PB
};
static struct mcp23008_reg_name_t mcp23008_reg_name_g[MCP23008_MODULE_MAX] = {0};
static uint8_t __mcp23008_reg_value_get(struct mcp23008_set_para_t *mcp23008_ctrl_para)
{
@@ -55,14 +106,17 @@ static int __chip_MCP23008_i2c_write(struct mcp23008_set_para_t *mcp23008_ctrl_p
struct mcp23008_set_para_t *para = mcp23008_ctrl_para;
struct i2c_para_t i2c_send;
struct i2c_para_t *send = &i2c_send;
int ret;
send->i2c_txlen = 2;
send->i2c_rxlen = 0;
send->i2c_rxlen = 1;
send->i2c_addr = module_addr_g[para->chip_module] | MCP23008_WT_BIT;
memcpy(send->i2c_tx, &para->reg_addr, 1);
memcpy(&send->i2c_tx[1], &para->val, 1);
return i2c0_write(send);
ret = i2c0_write(send);
return ret;
}
static uint8_t __chip_MCP23008_i2c_read(struct mcp23008_set_para_t *mcp23008_ctrl_para)
@@ -95,7 +149,7 @@ int chip_MCP23008_set(enum mcp23008_module_e i2c_module, enum mcp23008_reg_name_
uint8_t v = value;
uint8_t set_val = 0;
if (modul > MCP23008_MODULE_MAX)
if (modul >= MCP23008_MODULE_MAX)
return -1;
if (reg >= MCP23008_REG_MAX)
@@ -144,6 +198,8 @@ uint8_t chip_MCP23008_rd_reg_stat(enum mcp23008_module_e i2c_module, enum mcp230
para->reg_addr = reg;
__chip_MCP23008_i2c_read(para);
return para->val;
}
@@ -0,0 +1,25 @@
#ifndef I2C_CTRL_H
#define I2C_CTRL_H
#ifdef __cplusplus
extern "C" {
#endif
#define I2C_100K 0
#define I2C_400K 1
struct i2c_para_t {
uint8_t i2c_addr;
uint8_t i2c_txlen;
uint8_t i2c_rxlen;
uint8_t i2c_tx[256];
uint8_t i2c_rx[256];
};
int i2c0_open(uint8_t bitRate);
int i2c0_write(struct i2c_para_t *i2c_para);
#ifdef __cplusplus
}
#endif
#endif
@@ -0,0 +1,53 @@
#include <Board.h>
#include <ti/drivers/I2C.h>
#include "HAL/cc2650_driver/i2c_ctrl.h"
/* system use I2C parameters */
static I2C_Handle I2Chandle0 = NULL;
static I2C_Params I2CParams0;
/* Open the I2C driver */
int i2c0_open(uint8_t speed)
{
//ret=0 -> success
// =1 -> already exists
// =2 -> open fail
uint8_t s = speed;
I2C_BitRate rate;
if (I2Chandle0 != NULL)
return 1;
if (s == I2C_100K)
rate = I2C_100kHz;
else
rate = I2C_400kHz;
/* Configure I2C */
Board_initI2C();
I2C_Params_init(&I2CParams0);
I2CParams0.bitRate = rate;
/* Attempt to open I2C. */
I2Chandle0 = I2C_open(Board_I2C0, &I2CParams0);
if (I2Chandle0 == NULL)
return 2;
return 0;
}
int i2c0_write(struct i2c_para_t *i2c_para)
{
struct i2c_para_t *p = i2c_para;
I2C_Transaction I2C0Transaction;
I2C0Transaction.writeCount = p->i2c_txlen;
I2C0Transaction.writeBuf = p->i2c_tx;
I2C0Transaction.readCount = p->i2c_rxlen;
I2C0Transaction.readBuf = p->i2c_rx;
I2C0Transaction.slaveAddress = p->i2c_addr>>1;
return I2C_transfer(I2Chandle0, &I2C0Transaction) ? 0 : -1;
}
@@ -13,16 +13,14 @@ extern "C" {
#define SPI_CLK_10M 10000000
#define SPI_CLK_4M 4000000
bool spi0_open(uint32_t bitRate, uint8_t polarity, uint8_t phase);
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);
bool spi1_open(uint32_t bitRate, uint8_t polarity, uint8_t phase);
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
@@ -1,18 +1,43 @@
#include "driver/spi_ctrl.h"
#include <Board.h>
#include <ti/drivers/SPI.h>
#include "HAL/cc2650_driver/spi_ctrl.h"
/*
SPI bit rate in Hz.
Maximum bit rates supported by hardware:
+---------------+-----------------+------------------+
| Device Family | Slave Max (MHz) | Master Max (MHz) |
+---------------+-----------------+------------------+
| MSP432P4 | 16 MHz | 24 MHz |
| MSP432E4 | 10 MHz | 60 MHz |
| CC13XX/CC26XX | 4 MHz | 12 MHz |
| CC32XX | 20 MHz | 20 MHz |
+---------------+-----------------+------------------+
Please note that depending on the specific use case, the driver may not support the hardware's maximum bit rate.
*/
/* system use SPI parameters */
static SPI_Handle spiHandle0 = NULL;
static SPI_Params spiParams0;
/* system use SPI parameters */
static SPI_Handle spiHandle1 = NULL;
static SPI_Params spiParams1;
bool spi0_open(uint32_t bitRate, uint8_t polarity, uint8_t phase)
/* 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)
@@ -23,8 +48,9 @@ bool spi0_open(uint32_t bitRate, uint8_t polarity, uint8_t phase)
frameFormat = SPI_POL1_PHA1;
/* Configure SPI as master */
Board_initSPI();
SPI_Params_init(&spiParams0);
spiParams0.bitRate = bitRate;
spiParams0.bitRate = rate;
spiParams0.mode = SPI_MASTER;
spiParams0.dataSize = 8;
spiParams0.frameFormat = frameFormat;
@@ -32,7 +58,10 @@ bool spi0_open(uint32_t bitRate, uint8_t polarity, uint8_t phase)
/* Attempt to open SPI. */
spiHandle0 = SPI_open(Board_SPI0, &spiParams0);
return spiHandle0 != NULL;
if (spiHandle0 == NULL)
return 2;
return 0;
}
/* Close the RTOS SPI driver */
@@ -40,32 +69,44 @@ void spi0_close(void)
{
if (spiHandle0 != NULL)
{
// Close the RTOS driver
SPI_close(spiHandle0);
spiHandle0 = NULL;
}
return;
}
int spi0_write(uint8_t *rxBuf, uint8_t *txBuf, uint8_t len)
{
SPI_Transaction spi0Transaction;
//ret=0 -> success
// =1 -> fail
SPI_Transaction spi0Transaction;
spi0Transaction.count = len;
spi0Transaction.txBuf = txBuf;
spi0Transaction.arg = NULL;
spi0Transaction.rxBuf = NULL;
return SPI_transfer(spiHandle0, &spi0Transaction) ? 0 : -1;
if (SPI_transfer(spiHandle0, &spi0Transaction) == FALSE) //TRUE->sucess, FALSE->fail
return 1;
return 0;
}
/* Open the RTOS SPI driver */
bool spi1_open(uint32_t bitRate, uint8_t polarity, uint8_t phase)
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;
if (spiHandle1 != NULL)
return 1;
if (pol == 0 && pha == 0)
frameFormat = SPI_POL0_PHA0;
else if (pol == 0 && pha == 1)
@@ -76,6 +117,7 @@ bool spi1_open(uint32_t bitRate, uint8_t polarity, uint8_t phase)
frameFormat = SPI_POL1_PHA1;
/* Configure SPI as master */
Board_initSPI();
SPI_Params_init(&spiParams1);
spiParams1.bitRate = rate;
spiParams1.mode = SPI_MASTER;
@@ -85,6 +127,9 @@ bool spi1_open(uint32_t bitRate, uint8_t polarity, uint8_t phase)
/* Attempt to open SPI. */
spiHandle1 = SPI_open(Board_SPI1, &spiParams1);
if (spiHandle1 == NULL)
return 2;
return spiHandle1 != NULL;
}
@@ -93,20 +138,25 @@ void spi1_close(void)
{
if (spiHandle1 != NULL)
{
// Close the RTOS driver
SPI_close(spiHandle1);
spiHandle1 = NULL;
}
return;
}
int spi1_write(uint8_t *rxBuf, uint8_t *txBuf, uint8_t len)
{
SPI_Transaction spi1Transaction;
//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 SPI_transfer(spiHandle1, &spi1Transaction) ? 0 : -1;
return 0;
}
@@ -0,0 +1,92 @@
#ifndef BAT_10_CONF_H
#define BAT_10_CONF_H
#ifdef __cplusplus
extern "C" {
#endif
/* --------------------
* define device name
* ------------------*/
#define DEVICE_NAME "Elite-BAT"
#define MAJOR_PRODUCT_NUMBER 0
#define MINOR_PRODUCT_NUMBER 3
#define MAJOR_VERSION_NUMBER 1
#define MINOR_VERSION_NUMBER 1
/* ---------------------------
* define device buffer size
* -------------------------*/
#define CUSTOM_GATT_LENGTH
#define BLE_CIS_BUFF_SIZE 20
#define BLE_INS_BUFF_SIZE 20
#define BLE_DAT_BUFF_SIZE 40
/* -------------------
* define device pin
* -----------------*/
// Elite Pin Board
#define E_PIN_LED_SPI_CLK DIO5
#define E_PIN_LED_SPI_SDI DIO6
#define E_PIN_ADCA0 DIO0
#define E_PIN_ADCA1 DIO1
#define E_PIN_ADCA2 DIO7
#define E_PIN_SWCSBB DIO2
#define E_PIN_MEMCS DIO3
#define E_PIN_DIO4 DIO4
#define E_PIN_I2C_SCK DIO8
#define E_PIN_I2C_SDA DIO9
#define E_PIN_DACCS DIO10
#define E_PIN_ADCCS DIO11
#define E_PIN_SCLK0 DIO12
#define E_PIN_MOSI DIO13
#define E_PIN_MISO DIO14
// SPI & I2C Board
#define E_SPI0_MISO PIN_UNASSIGNED
#define E_SPI0_MOSI E_PIN_LED_SPI_SDI
#define E_SPI0_CLK E_PIN_LED_SPI_CLK
#define E_SPI0_CS PIN_UNASSIGNED
#define E_SPI1_MISO E_PIN_MISO
#define E_SPI1_MOSI E_PIN_MOSI
#define E_SPI1_CLK E_PIN_SCLK0
#define E_SPI1_CS PIN_UNASSIGNED
#define E_I2C0_SCL0 E_PIN_I2C_SCK
#define E_I2C0_SDA0 E_PIN_I2C_SDA
// no use
#define D0 PIN_UNASSIGNED
#define D1 PIN_UNASSIGNED
#define D2 PIN_UNASSIGNED
#define D3 PIN_UNASSIGNED
#define D4 PIN_UNASSIGNED
#define D5 PIN_UNASSIGNED
#define D6 PIN_UNASSIGNED
#define D7 PIN_UNASSIGNED
#define LOAD0 PIN_UNASSIGNED
#define LOAD1 PIN_UNASSIGNED
#define LOAD2 PIN_UNASSIGNED
#define SHUT_DOWN PIN_UNASSIGNED //switch_on
#define HIGH_Z LOAD0, PIN_UNASSIGNED
#define CS_MEM LOAD0, PIN_UNASSIGNED
#define CS_ADC LOAD0, PIN_UNASSIGNED
#define CS_DAC LOAD0, PIN_UNASSIGNED
#define MEM_HOLD LOAD1, PIN_UNASSIGNED
#define P_10V_enable LOAD1, PIN_UNASSIGNED
#define P_5V_enable LOAD1, PIN_UNASSIGNED
#define I_MID_ON LOAD2, PIN_UNASSIGNED
#define I_LARGE_ON LOAD2, PIN_UNASSIGNED
#define V_SMALL_ON LOAD2, PIN_UNASSIGNED
#define V_MID_ON LOAD2, PIN_UNASSIGNED
#define I_SMALL_ON LOAD2, PIN_UNASSIGNED
#define OFF LOAD2, PIN_UNASSIGNED //6994
#define VOUT_SMALL_ON LOAD2, PIN_UNASSIGNED
#ifdef __cplusplus
}
#endif
#endif
@@ -0,0 +1,159 @@
#ifndef APPLICATION_CONFIG_H
#define APPLICATION_CONFIG_H
#ifdef __cplusplus
extern "C" {
#endif
// !!! define DEF_ELITE_MODEL first please !!!
/*
*
* product number: MAJOR_PRODUCT_NUMBER, MINOR_PRODUCT_NUMBER, MAJOR_VERSION_NUMBER, MINOR_VERSION_NUMBER
* MAJOR_PRODUCT_NUMBER -> 0:Elite, 1:other serial
* Elite:
* MINOR_PRODUCT_NUMBER -> 1:legacy, 2:EDC, 3:BAT, 4:EIS, 5:TRIG, 6:MEGAFLY
*
* |------------------+------------------------+----------------------+-------------------------+----------------+----------------------+----------------------+----------+
* | hardware | model name | hw upper board | hw lower board | product number | device name | data server lib name | UI |
* |------------------+------------------------+----------------------+-------------------------+----------------+----------------------+----------------------+----------+
* | Elite EDC1.4 | DEF_ELITE_EDC_14 | Elite1.4-re Jun.2019 | Elite1.4-re Jun. 2019 | 0, 2, 1, 5 | "Elite-EDC" | Elite_EDC_1.4 | null |
* | Elite EDC1.5 | DEF_ELITE_EDC_15 | Elite1.5 Dec. 2019 | Elite1.5 Dec. 2019 | 0, 2, 1, 6 | "Elite-EDC" | Elite_EDC_1.5 | EliteEDC |
* | Elite EDC1.5re | DEF_ELITE_EDC_15RE | Elite1.5 Dec. 2019 | Elite1.5-re Jan. 2021 | 0, 2, 1, 7 | "Elite-EDC" | Elite_EDC_1.5re | EliteEDC |
* | Elite EDC1.5r2 | DEF_ELITE_EDC_15R2 | Elite1.5 Dec. 2019 | Elite1.5-r2 May. 2022 | 0, 2, 1, 8 | "Elite-EDC" | Elite_EDC_1.5r2 | EliteEDC |
* | Elite BAT0.1 | DEF_ELITE_BAT_01 | Elite2.0 Feb. 2022 | 0, 3, 1, 0 | "Elite-BAT" | Elite_BAT_0.1 | EliteEDC |
* | Elite BAT1.0 | DEF_ELITE_BAT_10 | BAT SMC V1.0 Aug.2022| BAT PWR V1.0 Aug. 2022 | 0, 3, 1, 1 | "Elite-BAT" | Elite_BAT_1.0 | EliteEDC |
* | Elite EIS1.0 | DEF_ELITE_EIS_10 | Elite1.5 Dec. 2019 | Elite EIS1.0 Aug. 2020 | 0, 4, 1, 0 | "Elite-EIS" | Elite_EIS_1.0 | EliteEIS |
* | Elite EIS1.1 | DEF_ELITE_EIS_11 | Elite1.5 Dec. 2019 | Elite EIS1.1 Feb. 2022 | 0, 4, 1, 1 | "Elite-EIS" | Elite_EIS_1.1 | EliteEIS |
* | Elite EISmini1.0 | DEF_ELITE_EIS_MINI_10 | EIS MINI May. 2022 | 0, 4, 1, 2 | "Elite-EIS-MINI" | Elite_EIS_MINI_1.0 | EliteEIS |
* | Elite TRIG0.1 | DEF_ELITE_TRIG_01 | Elite TRIG01 Jan. 2021 | 0, 5, 1, 0 | "Elite-TRIG" | Elite_TRIG_0.1 | EliteTrigger |
* | Elite MEGAFLY0.1 | DEF_ELITE_MEGAFLY_01 | Elite1.5 Dec. 2019 | Elite Megafly Sep. 2020 | 0, 6, 1, 0 | "Elite-MEGAFLY" | Elite_MEGAFLY_0.1 | null |
* |-----------------+------------------------+----------------------+-------------------------+----------------+----------------------+----------------------+----------+
* ps.
* model name is FW engineer defined
* device name is used for controller
*/
#define DEF_ELITE_EDC_14 0
#define DEF_ELITE_EDC_15 1
#define DEF_ELITE_EDC_15RE 2
#define DEF_ELITE_EDC_15R2 3
#define DEF_ELITE_BAT_01 4
#define DEF_ELITE_BAT_10 5
#define DEF_ELITE_EIS_10 6
#define DEF_ELITE_EIS_11 7
#define DEF_ELITE_EIS_MINI_10 8
#define DEF_ELITE_TRIG_01 9
#define DEF_ELITE_MEGAFLY_01 10
#define DEF_ELITE_MAX 11
#define DEF_ELITE_MODEL DEF_ELITE_BAT_10
#ifndef DEF_ELITE_MODEL
#error "DEF_ELITE_MODEL not defined"
#endif
// model information
#if (DEF_ELITE_MODEL == DEF_ELITE_EDC_14)
#error "code no support"
#elif (DEF_ELITE_MODEL == DEF_ELITE_EDC_15)
#error "code no support"
#elif (DEF_ELITE_MODEL == DEF_ELITE_EDC_15RE)
#error "code no support"
#elif (DEF_ELITE_MODEL == DEF_ELITE_EDC_15R2)
#error "code no support"
#elif (DEF_ELITE_MODEL == DEF_ELITE_BAT_01)
#error "code no support"
#elif (DEF_ELITE_MODEL == DEF_ELITE_BAT_10)
#include "BAT_10_conf.h"
#elif (DEF_ELITE_MODEL == DEF_ELITE_EIS_10)
#error "code no support"
#elif (DEF_ELITE_MODEL == DEF_ELITE_EIS_11)
#error "code no support"
#elif (DEF_ELITE_MODEL == DEF_ELITE_EIS_MINI_10)
#error "code no support"
#elif (DEF_ELITE_MODEL == DEF_ELITE_TRIG_01)
#error "code no support"
#elif (DEF_ELITE_MODEL == DEF_ELITE_MEGAFLY_01)
#error "code no support"
#else
#error "no this model"
#endif
// model information
// #if (DEF_ELITE_MODEL == DEF_ELITE_EDC_14)
// #define DEVICE_NAME "Elite-EDC"
// #define MAJOR_PRODUCT_NUMBER 0
// #define MINOR_PRODUCT_NUMBER 2
// #define MAJOR_VERSION_NUMBER 1
// #define MINOR_VERSION_NUMBER 5
// #elif (DEF_ELITE_MODEL == DEF_ELITE_EDC_15)
// #define DEVICE_NAME "Elite-EDC"
// #define MAJOR_PRODUCT_NUMBER 0
// #define MINOR_PRODUCT_NUMBER 2
// #define MAJOR_VERSION_NUMBER 1
// #define MINOR_VERSION_NUMBER 6
// #elif (DEF_ELITE_MODEL == DEF_ELITE_EDC_15RE)
// #define DEVICE_NAME "Elite-EDC"
// #define MAJOR_PRODUCT_NUMBER 0
// #define MINOR_PRODUCT_NUMBER 2
// #define MAJOR_VERSION_NUMBER 1
// #define MINOR_VERSION_NUMBER 7
// #elif (DEF_ELITE_MODEL == DEF_ELITE_EDC_15R2)
// #define DEVICE_NAME "Elite-EDC"
// #define MAJOR_PRODUCT_NUMBER 0
// #define MINOR_PRODUCT_NUMBER 2
// #define MAJOR_VERSION_NUMBER 1
// #define MINOR_VERSION_NUMBER 8
// #elif (DEF_ELITE_MODEL == DEF_ELITE_BAT_01)
// #define DEVICE_NAME "Elite-BAT"
// #define MAJOR_PRODUCT_NUMBER 0
// #define MINOR_PRODUCT_NUMBER 3
// #define MAJOR_VERSION_NUMBER 1
// #define MINOR_VERSION_NUMBER 0
// #elif (DEF_ELITE_MODEL == DEF_ELITE_BAT_10)
// #define DEVICE_NAME "Elite-BAT"
// #define MAJOR_PRODUCT_NUMBER 0
// #define MINOR_PRODUCT_NUMBER 3
// #define MAJOR_VERSION_NUMBER 1
// #define MINOR_VERSION_NUMBER 1
// #elif (DEF_ELITE_MODEL == DEF_ELITE_EIS_10)
// #define DEVICE_NAME "Elite-EIS"
// #define MAJOR_PRODUCT_NUMBER 0
// #define MINOR_PRODUCT_NUMBER 4
// #define MAJOR_VERSION_NUMBER 1
// #define MINOR_VERSION_NUMBER 0
// #elif (DEF_ELITE_MODEL == DEF_ELITE_EIS_11)
// #define DEVICE_NAME "Elite-EIS"
// #define MAJOR_PRODUCT_NUMBER 0
// #define MINOR_PRODUCT_NUMBER 4
// #define MAJOR_VERSION_NUMBER 1
// #define MINOR_VERSION_NUMBER 1
// #elif (DEF_ELITE_MODEL == DEF_ELITE_EIS_MINI_10)
// #define DEVICE_NAME "Elite-EIS"
// #define MAJOR_PRODUCT_NUMBER 0
// #define MINOR_PRODUCT_NUMBER 4
// #define MAJOR_VERSION_NUMBER 1
// #define MINOR_VERSION_NUMBER 2
// #elif (DEF_ELITE_MODEL == DEF_ELITE_TRIG_01)
// #define DEVICE_NAME "Elite-TRIG"
// #define MAJOR_PRODUCT_NUMBER 0
// #define MINOR_PRODUCT_NUMBER 5
// #define MAJOR_VERSION_NUMBER 1
// #define MINOR_VERSION_NUMBER 0
// #elif (DEF_ELITE_MODEL == DEF_ELITE_MEGAFLY_01)
// #define DEVICE_NAME "Elite-MEGAFLY"
// #define MAJOR_PRODUCT_NUMBER 0
// #define MINOR_PRODUCT_NUMBER 6
// #define MAJOR_VERSION_NUMBER 1
// #define MINOR_VERSION_NUMBER 0
// #else
// #error "no this model"
// #endif
#ifdef __cplusplus
}
#endif
#endif
@@ -1,10 +0,0 @@
#define DEF_ELITE_EDC_2_0
#if defined (DEF_ELITE_EDC_1_5_RE)
#include "boards_config/pin_config_edc15re.h"
#elif defined (DEF_ELITE_EDC_1_5)
#include "boards_config/pin_config_edc15.h"
#elif defined (DEF_ELITE_EDC_2_0)
#include "boards_config/pin_config_edc20.h"
#endif
@@ -1,45 +0,0 @@
#define D0 DIO3
#define D1 DIO4
#define D2 DIO5
#define D3 DIO6
#define D4 DIO7
#define D5 DIO8
#define D6 DIO9
#define D7 DIO10
#define LOAD0 DIO13
#define LOAD1 DIO12
#define LOAD2 DIO11
#define SHUT_DOWN DIO14
/* SPI Board */
#define Board_SPI0_MISO PIN_UNASSIGNED
#define Board_SPI0_MOSI D1
#define Board_SPI0_CLK D0
#define Board_SPI0_CS PIN_UNASSIGNED
#define Board_SPI1_MISO DIO1
#define Board_SPI1_MOSI D3
#define Board_SPI1_CLK D2
#define Board_SPI1_CS PIN_UNASSIGNED
#define CS_ADC LOAD0, D6
#define CS_DAC LOAD0, D7
#define MOSI LOAD0, D3
#define SCLK LOAD0, D2
#define LED_MOSI_A LOAD0, D1
#define LED_SCLK_A LOAD0, D0
#define CS_MEM LOAD0, D5
#define MEM_HOLD LOAD0, D4
#define HIGH_Z LOAD2, D5
#define I_MID_ON LOAD2, D0
#define I_SMALL_ON LOAD2, D4
#define I_LARGE_ON LOAD2, D1
#define V_SMALL_ON LOAD2, D2
#define V_MID_ON LOAD2, D3
#define VOUT_SMALL_ON LOAD2, D7
#define OFF LOAD2, D6
#define P_10V_enable LOAD1, D5
#define P_5V_enable LOAD1, D6
@@ -1,46 +0,0 @@
#define D0 DIO3
#define D1 DIO4
#define D2 DIO5
#define D3 DIO6
#define D4 DIO7
#define D5 DIO8
#define D6 DIO9
#define D7 DIO10
#define LOAD0 DIO13
#define LOAD1 DIO12
#define LOAD2 DIO11
#define SHUT_DOWN DIO14 //switch_on
/* SPI Board */
#define Board_SPI0_MISO PIN_UNASSIGNED
#define Board_SPI0_MOSI D1
#define Board_SPI0_CLK D0
#define Board_SPI0_CS PIN_UNASSIGNED
#define Board_SPI1_MISO DIO1
#define Board_SPI1_MOSI D3
#define Board_SPI1_CLK D2
#define Board_SPI1_CS PIN_UNASSIGNED
#define LED_SCLK_A LOAD0, D0
#define LED_MOSI_A LOAD0, D1
#define SCLK LOAD0, D2
#define MOSI LOAD0, D3
#define HIGH_Z LOAD0, D4
#define CS_MEM LOAD0, D5
#define CS_ADC LOAD0, D6
#define CS_DAC LOAD0, D7
#define MEM_HOLD LOAD1, D0
#define P_10V_enable LOAD1, D5
#define P_5V_enable LOAD1, D6
#define I_MID_ON LOAD2, D0
#define I_LARGE_ON LOAD2, D1
#define V_SMALL_ON LOAD2, D2
#define V_MID_ON LOAD2, D3
#define I_SMALL_ON LOAD2, D4
#define OFF LOAD2, D6 //6994
#define VOUT_SMALL_ON LOAD2, D7
@@ -1,85 +0,0 @@
/* Elite Pin Board */
#define E_PIN_LED_SPI_CLK DIO5
#define E_PIN_LED_SPI_SDI DIO6
#define E_PIN_ADCA0 DIO0
#define E_PIN_ADCA1 DIO1
#define E_PIN_ADCA2 DIO7
#define E_PIN_SWCSBB DIO2
#define E_PIN_MEMCS DIO3
#define E_PIN_DIO4 DIO4
#define E_PIN_I2C_SCK DIO8
#define E_PIN_I2C_SDA DIO9
#define E_PIN_DACCS DIO10
#define E_PIN_ADCCS DIO11
#define E_PIN_SCLK0 DIO12
#define E_PIN_MOSI DIO13
#define E_PIN_MISO DIO14
/* SPI Board */
#define Board_SPI0_MISO PIN_UNASSIGNED
#define Board_SPI0_MOSI E_PIN_LED_SPI_SDI
#define Board_SPI0_CLK E_PIN_LED_SPI_CLK
#define Board_SPI0_CS PIN_UNASSIGNED
#define Board_SPI1_MISO E_PIN_MISO
#define Board_SPI1_MOSI E_PIN_MOSI
#define Board_SPI1_CLK E_PIN_SCLK0
#define Board_SPI1_CS PIN_UNASSIGNED
/* I2C */
#define Board_I2C0_SCL0 E_PIN_I2C_SCK
#define Board_I2C0_SDA0 E_PIN_I2C_SDA
#define D0 PIN_UNASSIGNED
#define D1 PIN_UNASSIGNED
#define D2 PIN_UNASSIGNED
#define D3 PIN_UNASSIGNED
#define D4 PIN_UNASSIGNED
#define D5 PIN_UNASSIGNED
#define D6 PIN_UNASSIGNED
#define D7 PIN_UNASSIGNED
#define LOAD0 PIN_UNASSIGNED
#define LOAD1 PIN_UNASSIGNED
#define LOAD2 PIN_UNASSIGNED
#define SHUT_DOWN PIN_UNASSIGNED //switch_on
// #define ADC_CS DIO11
//#define DAC_CS DIO10
#define HIGH_Z LOAD0, PIN_UNASSIGNED
#define CS_MEM LOAD0, PIN_UNASSIGNED
#define CS_ADC LOAD0, PIN_UNASSIGNED
#define CS_DAC LOAD0, PIN_UNASSIGNED
#define MEM_HOLD LOAD1, PIN_UNASSIGNED
#define P_10V_enable LOAD1, PIN_UNASSIGNED
#define P_5V_enable LOAD1, PIN_UNASSIGNED
#define I_MID_ON LOAD2, PIN_UNASSIGNED
#define I_LARGE_ON LOAD2, PIN_UNASSIGNED
#define V_SMALL_ON LOAD2, PIN_UNASSIGNED
#define V_MID_ON LOAD2, PIN_UNASSIGNED
#define I_SMALL_ON LOAD2, PIN_UNASSIGNED
#define OFF LOAD2, PIN_UNASSIGNED //6994
#define VOUT_SMALL_ON LOAD2, PIN_UNASSIGNED
@@ -1,109 +0,0 @@
#ifndef MCP23008_H
#define MCP23008_H
#ifdef __cplusplus
extern "C" {
#endif
//i2c addr
/************************************************************************************************
* .h
************************************************************************************************/
/*
* Register addresses
* +---------+-------------------+
* | Address | Access to: |
* +---------+-------------------+
* | 00h | IODIR |
* | 01h | IPOL |
* | 02h | GPINTEN |
* | 03h | DEFVAL |
* | 04h | INTCON |
* | 05h | IOCON |
* | 06h | GPPU |
* | 07h | INTF |
* | 08h | INTCAP(Read-only) |
* | 09h | GPIO |
* | 0Ah | OLAT |
* +---------+-------------------+
*/
#define MCP23008_WT_BIT 0
#define MCP23008_RD_BIT 1
#define GET_INPUT_SW_SEN() ((chip_MCP23008_rd_reg_stat(MCP23008_MODULE_U503, MCP23008_REG_GPIO) & 0x40) >> 6)
#define PUSH_KEY (GET_INPUT_SW_SEN() == 0)
#define SET_VLOGIC_EN_GPIO(_v) (chip_MCP23008_set(MCP23008_MODULE_U503, MCP23008_REG_GPIO, MCP23008_P4, _v))
#define SET_VLOGIC_EN_IODIR(_v) (chip_MCP23008_set(MCP23008_MODULE_U503, MCP23008_REG_IODIR, MCP23008_P4, _v))
#define SET_SW_EN_GPIO(_v) (chip_MCP23008_set(MCP23008_MODULE_U503, MCP23008_REG_GPIO, MCP23008_P5, _v))
enum mcp23008_module_e {
MCP23008_MODULE_U503 = 0,
MCP23008_MODULE_U505,
MCP23008_MODULE_MAX,
};
enum mcp23008_reg_name_e {
MCP23008_REG_IODIR = 0x00,
MCP23008_REG_IPOL,
MCP23008_REG_GPINTEN,
MCP23008_REG_DEFVAL,
MCP23008_REG_INTCON,
MCP23008_REG_IOCON,
MCP23008_REG_GPPU,
MCP23008_REG_INTF,
MCP23008_REG_INTCAP,
MCP23008_REG_GPIO,
MCP23008_REG_OLAT,
MCP23008_REG_MAX,
};
enum mcp23008_gpio_e {
MCP23008_P0 = 0,
MCP23008_P1,
MCP23008_P2,
MCP23008_P3,
MCP23008_P4,
MCP23008_P5,
MCP23008_P6,
MCP23008_P7,
MCP23008_PIN_ALL,
};
struct mcp23008_reg_name_t {
uint8_t iodir;
uint8_t gpio;
};
struct mcp23008_set_para_t {
enum mcp23008_module_e chip_module;
enum mcp23008_reg_name_e reg_addr;
uint8_t val;
};
static struct mcp23008_reg_name_t mcp23008_reg_name_g[MCP23008_MODULE_MAX] = {0};
static uint8_t module_addr_g[MCP23008_MODULE_MAX] = {
0x46, // MCP23008_MODULE_U503
0x4C, // MCP23008_MODULE_U505
};
int chip_MCP23008_set(enum mcp23008_module_e i2c_module, enum mcp23008_reg_name_e reg_address, enum mcp23008_gpio_e wt_bit, uint8_t value);
uint8_t chip_MCP23008_rd_reg_stat(enum mcp23008_module_e i2c_module, enum mcp23008_reg_name_e reg_address);
#ifdef __cplusplus
}
#endif
#endif
@@ -2,11 +2,11 @@
#ifndef VERSION_DATE
#define VERSION_DATE
#define VERSION_DATE_YEAR 22
#define VERSION_DATE_MONTH 6
#define VERSION_DATE_DAY 9
#define VERSION_DATE_HOUR 10
#define VERSION_DATE_MINUTE 32
#define VERSION_DATE_YEAR 23
#define VERSION_DATE_MONTH 3
#define VERSION_DATE_DAY 16
#define VERSION_DATE_HOUR 13
#define VERSION_DATE_MINUTE 40
// this is NOT the version hash !!
// it's the last version hash
@@ -903,7 +903,7 @@ static void ins_decode_vis(uint8_t *ins_buf)
if (PeriodicEvent) {
WORKLED();
} else if (!PeriodicEvent) {
LEDPowerON();
checkFlafLED();
}
break;
}
@@ -1,5 +1,5 @@
#include "hardware/DAC_MAX5136.h"
#include "HAL/cc2650_driver/i2c_ctrl.h"
#include "HAL/MAX5136x2.h"
/*
* MODE_DEV_TOOL 0xFF
* DEV_TOOL_VERSION [34 LL FF 01]
@@ -40,6 +40,9 @@ enum dev_tool_para_e {
DEV_TOOL_SPI = 0x20,
DEV_TOOL_I2C = 0x28,
DEV_TOOL_GPIO_EDC20_ADC_CH = 0x31,
DEV_TOOL_MCP23008_PB = 0x32,
DEV_TOOL_MCP23008_PA = 0x33,
DEV_TOOL_MCP23008_RD = 0x34,
DEV_TOOL_OUT0_WRITE_THROUGH = 0x50,
DEV_TOOL_SWITCH_SELECT = 0x60,
};
@@ -207,7 +210,7 @@ static void dev_tool_i2c(uint8_t *ins_buf)
i2c0_write(send);
initCISBuf();
cis_buf[0] = send->i2c_rxlen + 1; //data len
cis_buf[0] = send->i2c_rxlen + 2; //data len
cis_buf[1] = DEV_TOOL_I2C;
memcpy(&cis_buf[2], send->i2c_rx, send->i2c_rxlen);
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, BLE_CIS_BUFF_SIZE, cis_buf);
@@ -259,7 +262,80 @@ static void dev_tool_switch_select(uint8_t *ins_buf)
switch_ctrl(switch_module_number, enable_type);
}
static void dev_tool_mcp23008_pb(uint8_t *ins_buf) //3000FF32
{
uint8_t *p = ins_buf;
enum mcp23008_gpio_e pin_n = (enum mcp23008_gpio_e)p[4]; // 0x00~0x07: PBx
uint8_t register_n = p[5]; // 0x00:IODIR 0x09:GPIO
uint8_t _v = p[6]; // 0:low 1:hogh 0:output 1:input
uint8_t re_val = 0;
if (register_n == 9) { // gpio:high/low
chip_MCP23008_set(MCP23008_MODULE_U503, MCP23008_REG_GPIO, pin_n, _v);
re_val = chip_MCP23008_rd_reg_stat(MCP23008_MODULE_U503, MCP23008_REG_GPIO);
} else if (register_n == 0) { // iodir:input-1/output-0
chip_MCP23008_set(MCP23008_MODULE_U503, MCP23008_REG_IODIR, pin_n, _v);
re_val = chip_MCP23008_rd_reg_stat(MCP23008_MODULE_U503, MCP23008_REG_IODIR);
}
initCISBuf();
cis_buf[0] = 2; //data len
cis_buf[1] = DEV_TOOL_MCP23008_PB;
memcpy(&cis_buf[2], &re_val, 1);
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, BLE_CIS_BUFF_SIZE, cis_buf);
}
static void dev_tool_mcp23008_pa(uint8_t *ins_buf) //3000FF33
{
uint8_t *p = ins_buf;
enum mcp23008_gpio_e pin_n = (enum mcp23008_gpio_e)p[4]; // 0x00~0x07: PAx
uint8_t register_n = p[5]; // 0x00:IODIR 0x09:GPIO
uint8_t _v = p[6]; // 0:low 1:hogh 0:output 1:input
uint8_t re_val = 0;
if (register_n == 9) { // gpio:high/low
chip_MCP23008_set(MCP23008_MODULE_U505, MCP23008_REG_GPIO, pin_n, _v);
re_val = chip_MCP23008_rd_reg_stat(MCP23008_MODULE_U505, MCP23008_REG_GPIO);
} else if (register_n == 0) { // iodir:input-1/output-0
chip_MCP23008_set(MCP23008_MODULE_U505, MCP23008_REG_IODIR, pin_n, _v);
re_val = chip_MCP23008_rd_reg_stat(MCP23008_MODULE_U505, MCP23008_REG_IODIR);
}
initCISBuf();
cis_buf[0] = 2; //data len
cis_buf[1] = DEV_TOOL_MCP23008_PA;
memcpy(&cis_buf[2], &re_val, 1);
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, BLE_CIS_BUFF_SIZE, cis_buf);
}
static void dev_tool_mcp23008_rd(uint8_t *ins_buf) //3000FF34
{
uint8_t *p = ins_buf;
uint8_t register_n = p[4]; // 0x00:IODIR 0x09:GPIO
uint8_t re_val = 0;
initCISBuf();
cis_buf[0] = 5; //data len
cis_buf[1] = DEV_TOOL_MCP23008_RD;
if (register_n == 9) { // gpio:high/low
re_val = chip_MCP23008_rd_reg_stat(MCP23008_MODULE_U505, MCP23008_REG_GPIO);
memcpy(&cis_buf[2], &re_val, 1);
re_val = chip_MCP23008_rd_reg_stat(MCP23008_MODULE_U503, MCP23008_REG_GPIO);
memcpy(&cis_buf[3], &re_val, 1);
} else if (register_n == 0) { // iodir:input-1/output-0
re_val = chip_MCP23008_rd_reg_stat(MCP23008_MODULE_U505, MCP23008_REG_IODIR);
memcpy(&cis_buf[2], &re_val, 1);
re_val = chip_MCP23008_rd_reg_stat(MCP23008_MODULE_U503, MCP23008_REG_IODIR);
memcpy(&cis_buf[3], &re_val, 1);
}
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, BLE_CIS_BUFF_SIZE, cis_buf);
}
static void mode_dev_tool(uint8_t *ins_buf)
{
@@ -302,8 +378,15 @@ static void mode_dev_tool(uint8_t *ins_buf)
case DEV_TOOL_SWITCH_SELECT:
dev_tool_switch_select(p);
break;
case DEV_TOOL_MCP23008_PB:
dev_tool_mcp23008_pb(p);
break;
case DEV_TOOL_MCP23008_PA:
dev_tool_mcp23008_pa(p);
break;
case DEV_TOOL_MCP23008_RD:
dev_tool_mcp23008_rd(p);
break;
default:
break;
@@ -50,15 +50,9 @@
#include <xdc/runtime/Error.h>
#include <ti/drivers/Power.h>
#include <ti/drivers/power/PowerCC26XX.h>
#include <ti/sysbios/BIOS.h>
#include <ti/drivers/SPI.h>
#include <ti/drivers/spi/SPICC26XXDMA.h>
#include <ti/drivers/dma/UDMACC26XX.h>
#include <ti/drivers/I2C.h>
#include <ti/drivers/i2c/I2CCC26XX.h>
#include "icall.h"
#include "hal_assert.h"
@@ -138,7 +132,7 @@ PIN_Handle radCtrlHandle;
extern void AssertHandler(uint8 assertCause, uint8 assertSubcause);
//extern Display_Handle dispHandle;
// extern Display_Handle dispHandle;
/*******************************************************************************
* @fn Main
@@ -253,48 +247,49 @@ 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;
//
// 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;
// }
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;
}
*/
return;
}
@@ -9,7 +9,7 @@
Target Device: CC2650, CC2640
******************************************************************************
Copyright (c) 2010-2018, Texas Instruments Incorporated
All rights reserved.
@@ -135,6 +135,7 @@ 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*/
@@ -143,12 +144,13 @@ 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;
@@ -157,9 +159,11 @@ 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;
@@ -168,9 +172,11 @@ 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;
@@ -179,6 +185,7 @@ 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
@@ -188,6 +195,7 @@ 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;
@@ -222,17 +230,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
@@ -246,114 +254,112 @@ static gattAttribute_t simpleProfileAttrTbl[SERVAPP_NUM_ATTR_SUPPORTED] =
// Characteristic Value 2
{
{ ATT_BT_UUID_SIZE, simpleProfilechar2UUID },
GATT_PERMIT_READ,
0,
simpleProfileChar2
},
// Characteristic 2 User Description
{
{ ATT_BT_UUID_SIZE, charUserDescUUID },
GATT_PERMIT_READ,
0,
simpleProfileChar2UserDesp
},
GATT_PERMIT_READ,
0,
simpleProfileChar2
},
// 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
@@ -395,7 +401,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 );
@@ -408,9 +414,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
{
@@ -468,7 +474,7 @@ bStatus_t SimpleProfile_SetParameter( uint8 param, uint8 len, void *value )
{
memcpy(simpleProfileChar1, value, len);
// simpleProfileChar1 = *((uint8*)value);
}
}
else
{
ret = bleInvalidRange;
@@ -482,7 +488,7 @@ bStatus_t SimpleProfile_SetParameter( uint8 param, uint8 len, void *value )
// simpleProfileChar2 = *((uint8*)value);
}
else
{
{
ret = bleInvalidRange;
}
break;
@@ -491,7 +497,8 @@ 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;
@@ -502,9 +509,12 @@ 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
{
@@ -513,8 +523,9 @@ 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
{
@@ -543,37 +554,41 @@ 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);
break;
memcpy(value, simpleProfileChar3, SIMPLEPROFILE_CHAR3_LEN);
// *((uint8*)value) = simpleProfileChar3;
break;
case SIMPLEPROFILE_CHAR4:
memcpy(value, simpleProfileChar4, SIMPLEPROFILE_CHAR4_LEN);
break;
memcpy(value, simpleProfileChar4, SIMPLEPROFILE_CHAR4_LEN);
// *((uint8*)value) = simpleProfileChar4;
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 );
}
/*********************************************************************
@@ -591,62 +606,65 @@ 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);
// 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 );
case SIMPLEPROFILE_CHAR2_UUID:
*pLen = SIMPLEPROFILE_CHAR2_LEN;
VOID memcpy( pValue, pAttr->pValue, SIMPLEPROFILE_CHAR2_LEN );
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;
}
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);
return ( status );
}
/*********************************************************************
@@ -663,83 +681,83 @@ static bStatus_t simpleProfile_ReadAttrCB(uint16_t connHandle, gattAttribute_t *
*
* @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) {
// 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;
}
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:
//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;
//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;
}
}
else
{
status = ATT_ERR_ATTR_NOT_LONG;
}
} 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);
}
//Write the value
if ( status == SUCCESS )
{
uint8 *pCurValue = (uint8 *)pAttr->pValue;
*pCurValue = pValue[0];
return (status);
// 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 == 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;
}
// 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 );
}
/*********************************************************************
@@ -56,7 +56,7 @@ extern "C"
/*********************************************************************
* INCLUDES
*/
#include "application_config/application_config.h"
/*********************************************************************
* CONSTANTS
*/
@@ -81,12 +81,24 @@ extern "C"
// Simple Keys Profile Services bit fields
#define SIMPLEPROFILE_SERVICE 0x00000001
#ifndef CUSTOM_GATT_LENGTH
// Length of Characteristic 5 in bytes
#define SIMPLEPROFILE_CHAR5_LEN 5
/*user insert*/
#define SIMPLEPROFILE_CHAR4_LEN 40
#define SIMPLEPROFILE_CHAR4_LEN 20
#define SIMPLEPROFILE_CHAR3_LEN 20
#define SIMPLEPROFILE_CHAR2_LEN 20
#define SIMPLEPROFILE_CHAR1_LEN 20
#else
/*user insert*/
#define SIMPLEPROFILE_CHAR5_LEN 5
#define SIMPLEPROFILE_CHAR4_LEN BLE_DAT_BUFF_SIZE
#define SIMPLEPROFILE_CHAR3_LEN BLE_INS_BUFF_SIZE
#define SIMPLEPROFILE_CHAR2_LEN BLE_CIS_BUFF_SIZE
#define SIMPLEPROFILE_CHAR1_LEN 20
#define BLE_CIS_BUFF_CHAR SIMPLEPROFILE_CHAR2
#define BLE_INS_BUFF_CHAR SIMPLEPROFILE_CHAR3
#define BLE_DAT_BUFF_CHAR SIMPLEPROFILE_CHAR4
#endif
/*********************************************************************
* TYPEDEFS
*/