27#include <zephyr/drivers/gpio.h>
28#include <zephyr/drivers/spi.h>
30#define VERSION_MAJOR 0
31#define VERSION_MINOR 15
33#define VERSION_DATE "BLE Sensor 07/20/26"
34#define BOARD_NAME "BLE Sensor Prototype"
36#define VERSION_DATE_EXT1 " (Bd 1.0 UART0)"
37#define VERSION_DATE_EXT2 " (Bd 1.0 No UART0)"
38#define VERSION_DATE_EXT3 " (Bd 1.0 NO SERIAL)"
39#define BOARD_NAME_EXT " V1.0 (nRF52832)"
44#define DEFAULT_DUTYCYCLE TEN_SECONDS
46#define SPI_BUF_SIZE 128
48#define SLOW_FREQ 150000
49#define FAST_FREQ 16000000
54#define EXPAND_AND_STR(x) STR(x)
56#define LOWTEMPENABLE 0x01
57#define LOWTEMPACTIVE 0x02
58#define HIGHTEMPENABLE 0x04
59#define HIGHTEMPACTIVE 0x08
60#define LOWHUMIDITYENABLE 0x01
61#define LOWHUMIDITYACTIVE 0x02
62#define HIGHHUMIDITYENABLE 0x04
63#define HIGHHUMIDITYACTIVE 0x08
75#define MAX_PARAMETERS 3
76#define MAX_FLASH_BYTES 0x200
77#define FLASHPARAMETERSTART 0
78#define FLASHBLESTART (FLASHPARAMETERSTART + 0x10)
79#define FLASHPARAMETERKEY 0X12345678
82#define MAX_NUMBER_BLE_PACKETS 10
160int myPrintk(
char *restrict fmt, ...);
170void hdc2080_rdy_seen(
const struct device *dev,
struct gpio_callback *cb, uint32_t pins);
171void sw2_seen(
const struct device *dev,
struct gpio_callback *cb, uint32_t pins);
185void flashxWritePage(uint32_t page, uint32_t address, uint8_t *data, uint16_t count);
203extern const struct device *
const i2c_dev;
204extern const struct device *
const uart0_dev;
213extern struct spi_buf
tx_bufs[];
214extern struct spi_buf
rx_bufs[];
217extern const struct spi_buf_set
tx;
218extern const struct spi_buf_set
rx;
219extern const struct spi_cs_control
spi_cs1;
220extern const struct spi_cs_control
spi_cs2;
221extern const struct gpio_dt_spec
spics1n;
222extern const struct gpio_dt_spec
spics2n;
223extern const struct device *
const spi_dev;
227extern const struct gpio_dt_spec
baten;
BME68X Sensor API header file.
uint8_t flashReadIn[MAX_FLASH_BYTES]
struct spi_config spi_cfg1
SPI configuration.
struct spi_buf tx_bufs[]
SPI TX buffer structure.
const struct spi_buf_set rx
SPI RX buffer structure.
const struct spi_cs_control spi_cs2
uint8_t buffer_rx[SPI_BUF_SIZE+8]
SPI receive buffer0.
const struct device *const spi_dev
flashParametersStruct flashParameters
working valuses of flash parameters in RAM
uint32_t sensorTypePresentAll
float adc_voltage[2]
last ADC voltage read [0] battery
const struct gpio_dt_spec spics2n
struct spi_config spi_cfg2
SPI configuration.
uint8_t buffer_tx[SPI_BUF_SIZE+8]
SPI transmit buffer.
uint8_t sendingDeviceInfo
flag to indicate sending device info in BLE packet instead of sensor data
uint8_t stopWDTFeed
stop Watch Dog Timer feed causing a WDT interrupt for testing
long long gatewayDateTime
char * cmdLineParameter[MAX_PARAMETERS]
array of pointers to command line parameter strings
const struct spi_cs_control spi_cs1
struct bme68x_dev bme688_dev
BME688 device.
struct bme68x_data BME688Data
struct spi_buf rx_bufs[]
SPI RX buffer structure.
const struct spi_buf_set tx
SPI TX buffer structure.
const struct gpio_dt_spec spics1n
int myPrintk(char *restrict fmt,...)
void sw2_seen(const struct device *dev, struct gpio_callback *cb, uint32_t pins)
Callback function for SW2 button.
int initBME688(void)
Initializes the BME688 sensor over SPI. Performs interface initialization, device reset,...
void displayFlashxParameters(void)
displays the NV flash parameters.
int8_t getCLICmd(char *line)
parses command line to find position of command in validCLICmds array.
void flashxClearParameters(void)
clears/initializes the flash parameters in RAM
int initW25Q64JV(void)
Initiailizes the W25Q64JW.
int myPrintkS(char *restrict fmt,...)
prints a status message to the UART
void flashxWritePage(uint32_t page, uint32_t address, uint8_t *data, uint16_t count)
writes data to address in serial flash over the SPI bus.
void readNVFlashxID(uint8_t *flashId)
reads the NV Flash ID over the SPI bus.
struct k_sem uart_rx_disabled_sem
struct k_sem hdc_rdy_seen
int adc_sample(void)
get a single reading from ADC channel
void flashxEraseBlock1(uint32_t address)
erases a 2K block page over the SPI bus.
int myPrintkI(char *restrict fmt,...)
prints an information message to the UART
void flashxReadPage(uint32_t address, uint8_t *flashRead)
reads a 256 byte page over the SPI bus.
void flashxErasePage(uint32_t address)
erases a 256 byte page over the SPI bus.
void hdc2080_rdy_seen(const struct device *dev, struct gpio_callback *cb, uint32_t pins)
Callback function for HDC2080 RDY pin.
const struct device *const i2c_dev
get the device structure for the I2C device defined by I2C_DEV_NODE
int myPrintkE(char *restrict fmt,...)
prints an error message to the UART
void flashxEraseSector(uint32_t address)
erases a 256K byte sector over the SPI bus.
void flashxFillPage(uint32_t address, uint16_t data)
fills a 256 byte page with data over the SPI bus.
const struct gpio_dt_spec baten
get the GPIO specification for the BATEN pin defined by BATEN_NODE
uint8_t bleCommand(uint8_t *data)
Executes a BLE command.
void rescan(void)
rescan all I2C and SPI devices
int getBME688Data(int count, uint8_t quiet)
Triggers and retrieves measurement data from the BME688.
int init_i2c()
Initializes the I2C interface.
int initHDC2080(void)
Initializes the HDC2080 sensor with default parameters.
const struct device *const uart0_dev
void setFlashxParameters(uint8_t display)
loads the NV Flash parameters from teh RAM flash parameters
void flashxErase(void)
erases the entire 8 Mb over the SPI bus.
void readNVFlashxStatus(uint8_t *flashStatus)
reads the 3 NV Flash status registers over the SPI bus.
void executeCmd(char *line)
executes the command in line array.
void getFlashparameters(void)
Read the stored flash parameter block from serial flash.
int getCmd(uint8_t *line)
int myPrintkW(char *restrict fmt,...)
prints a warning message to the UART
void flashxEraseBlock2(uint32_t address)
void int64_to_string(int64_t num, char *str)
Converts a 64-bit signed integer to a null-terminated string.
Flash parameters structure.
uint8_t nouart0
no UART0 setting
char sensorName[40]
sensor name
uint16_t nextSavedRead
page address of next write JSON packet
char sensorID[7]
last 6 bytes of MAC address
uint8_t ignoreBME688
disable BME688 anywhere in the code for lower power consumption
uint8_t manualTrigger
disable HDC2080 interrups and trigger/read when datetime BLE command seen
uint16_t savedCount
number of saved JSON packets
uint16_t nextSavedWrite
page address of next write JSON packet
uint32_t dutyCycle
interval in seconds to send Sensor data to the cloud
char group[40]
group for this sensor
uint32_t key
0x12345678 valid key
char customer[40]
cutome name for this sensor
uint8_t silent
= 0 running messages on, = 1 running messages off
char location[40]
location of this sensor