Added const keywords

This commit is contained in:
Thomas Basler 2024-01-14 16:36:35 +01:00
parent 18485ffefd
commit a1f2c93cf6
10 changed files with 1171 additions and 1171 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1,96 +1,96 @@
/* /*
* THE FOLLOWING FIRMWARE IS PROVIDED: (1) "AS IS" WITH NO WARRANTY; AND * THE FOLLOWING FIRMWARE IS PROVIDED: (1) "AS IS" WITH NO WARRANTY; AND
* (2)TO ENABLE ACCESS TO CODING INFORMATION TO GUIDE AND FACILITATE CUSTOMER. * (2)TO ENABLE ACCESS TO CODING INFORMATION TO GUIDE AND FACILITATE CUSTOMER.
* CONSEQUENTLY, CMOSTEK SHALL NOT BE HELD LIABLE FOR ANY DIRECT, INDIRECT OR * CONSEQUENTLY, CMOSTEK SHALL NOT BE HELD LIABLE FOR ANY DIRECT, INDIRECT OR
* CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE CONTENT * CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE CONTENT
* OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING INFORMATION * OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING INFORMATION
* CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. * CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
* *
* Copyright (C) CMOSTEK SZ. * Copyright (C) CMOSTEK SZ.
*/ */
/*! /*!
* @file cmt2300a.h * @file cmt2300a.h
* @brief CMT2300A transceiver RF chip driver * @brief CMT2300A transceiver RF chip driver
* *
* @version 1.3 * @version 1.3
* @date Jul 17 2017 * @date Jul 17 2017
* @author CMOSTEK R@D * @author CMOSTEK R@D
*/ */
#ifndef __CMT2300A_H #ifndef __CMT2300A_H
#define __CMT2300A_H #define __CMT2300A_H
#include "cmt2300a_defs.h" #include "cmt2300a_defs.h"
#include "cmt2300a_hal.h" #include "cmt2300a_hal.h"
#include <stdint.h> #include <stdint.h>
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
#define ENABLE_AUTO_SWITCH_CHIP_STATUS /* Enable the auto switch chip status */ #define ENABLE_AUTO_SWITCH_CHIP_STATUS /* Enable the auto switch chip status */
/* ************************************************************************ /* ************************************************************************
The following are for chip status controls. The following are for chip status controls.
* ************************************************************************ */ * ************************************************************************ */
void CMT2300A_SoftReset(void); void CMT2300A_SoftReset(void);
uint8_t CMT2300A_GetChipStatus(void); uint8_t CMT2300A_GetChipStatus(void);
bool CMT2300A_AutoSwitchStatus(uint8_t nGoCmd); bool CMT2300A_AutoSwitchStatus(uint8_t nGoCmd);
bool CMT2300A_GoSleep(void); bool CMT2300A_GoSleep(void);
bool CMT2300A_GoStby(void); bool CMT2300A_GoStby(void);
bool CMT2300A_GoTFS(void); bool CMT2300A_GoTFS(void);
bool CMT2300A_GoRFS(void); bool CMT2300A_GoRFS(void);
bool CMT2300A_GoTx(void); bool CMT2300A_GoTx(void);
bool CMT2300A_GoRx(void); bool CMT2300A_GoRx(void);
/* ************************************************************************ /* ************************************************************************
* The following are for chip interrupts, GPIO, FIFO operations. * The following are for chip interrupts, GPIO, FIFO operations.
* ************************************************************************ */ * ************************************************************************ */
void CMT2300A_ConfigGpio(uint8_t nGpioSel); void CMT2300A_ConfigGpio(uint8_t nGpioSel);
void CMT2300A_ConfigInterrupt(uint8_t nInt1Sel, uint8_t nInt2Sel); void CMT2300A_ConfigInterrupt(uint8_t nInt1Sel, uint8_t nInt2Sel);
void CMT2300A_SetInterruptPolar(bool bActiveHigh); void CMT2300A_SetInterruptPolar(bool bActiveHigh);
void CMT2300A_SetFifoThreshold(uint8_t nFifoThreshold); void CMT2300A_SetFifoThreshold(uint8_t nFifoThreshold);
void CMT2300A_EnableAntennaSwitch(uint8_t nMode); void CMT2300A_EnableAntennaSwitch(uint8_t nMode);
void CMT2300A_EnableInterrupt(uint8_t nEnable); void CMT2300A_EnableInterrupt(uint8_t nEnable);
void CMT2300A_EnableRxFifoAutoClear(bool bEnable); void CMT2300A_EnableRxFifoAutoClear(bool bEnable);
void CMT2300A_EnableFifoMerge(bool bEnable); void CMT2300A_EnableFifoMerge(bool bEnable);
void CMT2300A_EnableReadFifo(void); void CMT2300A_EnableReadFifo(void);
void CMT2300A_EnableWriteFifo(void); void CMT2300A_EnableWriteFifo(void);
void CMT2300A_RestoreFifo(void); void CMT2300A_RestoreFifo(void);
uint8_t CMT2300A_ClearTxFifo(void); uint8_t CMT2300A_ClearTxFifo(void);
uint8_t CMT2300A_ClearRxFifo(void); uint8_t CMT2300A_ClearRxFifo(void);
uint8_t CMT2300A_ClearInterruptFlags(void); uint8_t CMT2300A_ClearInterruptFlags(void);
/* ************************************************************************ /* ************************************************************************
* The following are for Tx DIN operations in direct mode. * The following are for Tx DIN operations in direct mode.
* ************************************************************************ */ * ************************************************************************ */
void CMT2300A_ConfigTxDin(uint8_t nDinSel); void CMT2300A_ConfigTxDin(uint8_t nDinSel);
void CMT2300A_EnableTxDin(bool bEnable); void CMT2300A_EnableTxDin(bool bEnable);
void CMT2300A_EnableTxDinInvert(bool bEnable); void CMT2300A_EnableTxDinInvert(bool bEnable);
/* ************************************************************************ /* ************************************************************************
* The following are general operations. * The following are general operations.
* ************************************************************************ */ * ************************************************************************ */
bool CMT2300A_IsExist(void); bool CMT2300A_IsExist(void);
uint8_t CMT2300A_GetRssiCode(void); uint8_t CMT2300A_GetRssiCode(void);
int CMT2300A_GetRssiDBm(void); int CMT2300A_GetRssiDBm(void);
void CMT2300A_SetFrequencyChannel(uint8_t nChann); void CMT2300A_SetFrequencyChannel(const uint8_t nChann);
void CMT2300A_SetFrequencyStep(uint8_t nOffset); void CMT2300A_SetFrequencyStep(uint8_t nOffset);
void CMT2300A_SetPayloadLength(uint16_t nLength); void CMT2300A_SetPayloadLength(uint16_t nLength);
void CMT2300A_EnableLfosc(bool bEnable); void CMT2300A_EnableLfosc(bool bEnable);
void CMT2300A_EnableLfoscOutput(bool bEnable); void CMT2300A_EnableLfoscOutput(bool bEnable);
void CMT2300A_EnableAfc(bool bEnable); void CMT2300A_EnableAfc(bool bEnable);
void CMT2300A_SetAfcOvfTh(uint8_t afcOvfTh); void CMT2300A_SetAfcOvfTh(uint8_t afcOvfTh);
/* ************************************************************************ /* ************************************************************************
* The following are for chip initializes. * The following are for chip initializes.
* ************************************************************************ */ * ************************************************************************ */
bool CMT2300A_Init(void); bool CMT2300A_Init(void);
bool CMT2300A_ConfigRegBank(uint8_t base_addr, const uint8_t bank[], uint8_t len); bool CMT2300A_ConfigRegBank(uint8_t base_addr, const uint8_t bank[], uint8_t len);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
#endif #endif

View File

@ -1,76 +1,76 @@
/* /*
* THE FOLLOWING FIRMWARE IS PROVIDED: (1) "AS IS" WITH NO WARRANTY; AND * THE FOLLOWING FIRMWARE IS PROVIDED: (1) "AS IS" WITH NO WARRANTY; AND
* (2)TO ENABLE ACCESS TO CODING INFORMATION TO GUIDE AND FACILITATE CUSTOMER. * (2)TO ENABLE ACCESS TO CODING INFORMATION TO GUIDE AND FACILITATE CUSTOMER.
* CONSEQUENTLY, CMOSTEK SHALL NOT BE HELD LIABLE FOR ANY DIRECT, INDIRECT OR * CONSEQUENTLY, CMOSTEK SHALL NOT BE HELD LIABLE FOR ANY DIRECT, INDIRECT OR
* CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE CONTENT * CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE CONTENT
* OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING INFORMATION * OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING INFORMATION
* CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. * CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
* *
* Copyright (C) CMOSTEK SZ. * Copyright (C) CMOSTEK SZ.
*/ */
/*! /*!
* @file cmt2300a_hal.c * @file cmt2300a_hal.c
* @brief CMT2300A hardware abstraction layer * @brief CMT2300A hardware abstraction layer
* *
* @version 1.2 * @version 1.2
* @date Jul 17 2017 * @date Jul 17 2017
* @author CMOSTEK R@D * @author CMOSTEK R@D
*/ */
#include "cmt2300a_hal.h" #include "cmt2300a_hal.h"
#include "cmt_spi3.h" #include "cmt_spi3.h"
#include <Arduino.h> #include <Arduino.h>
/*! ******************************************************** /*! ********************************************************
* @name CMT2300A_InitSpi * @name CMT2300A_InitSpi
* @desc Initializes the CMT2300A SPI interface. * @desc Initializes the CMT2300A SPI interface.
* *********************************************************/ * *********************************************************/
void CMT2300A_InitSpi(int8_t pin_sdio, int8_t pin_clk, int8_t pin_cs, int8_t pin_fcs, uint32_t spi_speed) void CMT2300A_InitSpi(const int8_t pin_sdio, const int8_t pin_clk, const int8_t pin_cs, const int8_t pin_fcs, const uint32_t spi_speed)
{ {
cmt_spi3_init(pin_sdio, pin_clk, pin_cs, pin_fcs, spi_speed); cmt_spi3_init(pin_sdio, pin_clk, pin_cs, pin_fcs, spi_speed);
} }
/*! ******************************************************** /*! ********************************************************
* @name CMT2300A_ReadReg * @name CMT2300A_ReadReg
* @desc Read the CMT2300A register at the specified address. * @desc Read the CMT2300A register at the specified address.
* @param addr: register address * @param addr: register address
* @return Register value * @return Register value
* *********************************************************/ * *********************************************************/
uint8_t CMT2300A_ReadReg(uint8_t addr) uint8_t CMT2300A_ReadReg(const uint8_t addr)
{ {
return cmt_spi3_read(addr); return cmt_spi3_read(addr);
} }
/*! ******************************************************** /*! ********************************************************
* @name CMT2300A_WriteReg * @name CMT2300A_WriteReg
* @desc Write the CMT2300A register at the specified address. * @desc Write the CMT2300A register at the specified address.
* @param addr: register address * @param addr: register address
* dat: register value * dat: register value
* *********************************************************/ * *********************************************************/
void CMT2300A_WriteReg(uint8_t addr, uint8_t dat) void CMT2300A_WriteReg(const uint8_t addr, const uint8_t dat)
{ {
cmt_spi3_write(addr, dat); cmt_spi3_write(addr, dat);
} }
/*! ******************************************************** /*! ********************************************************
* @name CMT2300A_ReadFifo * @name CMT2300A_ReadFifo
* @desc Reads the contents of the CMT2300A FIFO. * @desc Reads the contents of the CMT2300A FIFO.
* @param buf: buffer where to copy the FIFO read data * @param buf: buffer where to copy the FIFO read data
* len: number of bytes to be read from the FIFO * len: number of bytes to be read from the FIFO
* *********************************************************/ * *********************************************************/
void CMT2300A_ReadFifo(uint8_t buf[], uint16_t len) void CMT2300A_ReadFifo(uint8_t buf[], const uint16_t len)
{ {
cmt_spi3_read_fifo(buf, len); cmt_spi3_read_fifo(buf, len);
} }
/*! ******************************************************** /*! ********************************************************
* @name CMT2300A_WriteFifo * @name CMT2300A_WriteFifo
* @desc Writes the buffer contents to the CMT2300A FIFO. * @desc Writes the buffer contents to the CMT2300A FIFO.
* @param buf: buffer containing data to be put on the FIFO * @param buf: buffer containing data to be put on the FIFO
* len: number of bytes to be written to the FIFO * len: number of bytes to be written to the FIFO
* *********************************************************/ * *********************************************************/
void CMT2300A_WriteFifo(const uint8_t buf[], uint16_t len) void CMT2300A_WriteFifo(const uint8_t buf[], const uint16_t len)
{ {
cmt_spi3_write_fifo(buf, len); cmt_spi3_write_fifo(buf, len);
} }

View File

@ -1,51 +1,51 @@
/* /*
* THE FOLLOWING FIRMWARE IS PROVIDED: (1) "AS IS" WITH NO WARRANTY; AND * THE FOLLOWING FIRMWARE IS PROVIDED: (1) "AS IS" WITH NO WARRANTY; AND
* (2)TO ENABLE ACCESS TO CODING INFORMATION TO GUIDE AND FACILITATE CUSTOMER. * (2)TO ENABLE ACCESS TO CODING INFORMATION TO GUIDE AND FACILITATE CUSTOMER.
* CONSEQUENTLY, CMOSTEK SHALL NOT BE HELD LIABLE FOR ANY DIRECT, INDIRECT OR * CONSEQUENTLY, CMOSTEK SHALL NOT BE HELD LIABLE FOR ANY DIRECT, INDIRECT OR
* CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE CONTENT * CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE CONTENT
* OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING INFORMATION * OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING INFORMATION
* CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. * CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
* *
* Copyright (C) CMOSTEK SZ. * Copyright (C) CMOSTEK SZ.
*/ */
/*! /*!
* @file cmt2300a_hal.h * @file cmt2300a_hal.h
* @brief CMT2300A hardware abstraction layer * @brief CMT2300A hardware abstraction layer
* *
* @version 1.2 * @version 1.2
* @date Jul 17 2017 * @date Jul 17 2017
* @author CMOSTEK R@D * @author CMOSTEK R@D
*/ */
#ifndef __CMT2300A_HAL_H #ifndef __CMT2300A_HAL_H
#define __CMT2300A_HAL_H #define __CMT2300A_HAL_H
#include <stdint.h> #include <stdint.h>
#include <Arduino.h> #include <Arduino.h>
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
/* ************************************************************************ /* ************************************************************************
* The following need to be modified by user * The following need to be modified by user
* ************************************************************************ */ * ************************************************************************ */
#define CMT2300A_DelayMs(ms) delay(ms) #define CMT2300A_DelayMs(ms) delay(ms)
#define CMT2300A_DelayUs(us) delayMicroseconds(us) #define CMT2300A_DelayUs(us) delayMicroseconds(us)
#define CMT2300A_GetTickCount() millis() #define CMT2300A_GetTickCount() millis()
/* ************************************************************************ */ /* ************************************************************************ */
void CMT2300A_InitSpi(int8_t pin_sdio, int8_t pin_clk, int8_t pin_cs, int8_t pin_fcs, uint32_t spi_speed); void CMT2300A_InitSpi(const int8_t pin_sdio, const int8_t pin_clk, const int8_t pin_cs, const int8_t pin_fcs, const uint32_t spi_speed);
uint8_t CMT2300A_ReadReg(uint8_t addr); uint8_t CMT2300A_ReadReg(const uint8_t addr);
void CMT2300A_WriteReg(uint8_t addr, uint8_t dat); void CMT2300A_WriteReg(const uint8_t addr, const uint8_t dat);
void CMT2300A_ReadFifo(uint8_t buf[], uint16_t len); void CMT2300A_ReadFifo(uint8_t buf[], const uint16_t len);
void CMT2300A_WriteFifo(const uint8_t buf[], uint16_t len); void CMT2300A_WriteFifo(const uint8_t buf[], const uint16_t len);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
#endif #endif

View File

@ -7,7 +7,7 @@
#include "cmt2300a_params_860.h" #include "cmt2300a_params_860.h"
#include "cmt2300a_params_900.h" #include "cmt2300a_params_900.h"
CMT2300A::CMT2300A(uint8_t pin_sdio, uint8_t pin_clk, uint8_t pin_cs, uint8_t pin_fcs, uint32_t spi_speed) CMT2300A::CMT2300A(const uint8_t pin_sdio, const uint8_t pin_clk, const uint8_t pin_cs, const uint8_t pin_fcs, const uint32_t spi_speed)
{ {
_pin_sdio = pin_sdio; _pin_sdio = pin_sdio;
_pin_clk = pin_clk; _pin_clk = pin_clk;
@ -58,7 +58,7 @@ bool CMT2300A::available(void)
) & CMT2300A_ReadReg(CMT2300A_CUS_INT_FLAG); ) & CMT2300A_ReadReg(CMT2300A_CUS_INT_FLAG);
} }
void CMT2300A::read(void* buf, uint8_t len) void CMT2300A::read(void* buf, const uint8_t len)
{ {
// Fetch the payload // Fetch the payload
CMT2300A_ReadFifo(static_cast<uint8_t*>(buf), len); CMT2300A_ReadFifo(static_cast<uint8_t*>(buf), len);
@ -66,7 +66,7 @@ void CMT2300A::read(void* buf, uint8_t len)
CMT2300A_ClearInterruptFlags(); CMT2300A_ClearInterruptFlags();
} }
bool CMT2300A::write(const uint8_t* buf, uint8_t len) bool CMT2300A::write(const uint8_t* buf, const uint8_t len)
{ {
CMT2300A_GoStby(); CMT2300A_GoStby();
CMT2300A_ClearInterruptFlags(); CMT2300A_ClearInterruptFlags();
@ -101,7 +101,7 @@ bool CMT2300A::write(const uint8_t* buf, uint8_t len)
return true; return true;
} }
void CMT2300A::setChannel(uint8_t channel) void CMT2300A::setChannel(const uint8_t channel)
{ {
CMT2300A_SetFrequencyChannel(channel); CMT2300A_SetFrequencyChannel(channel);
} }
@ -123,7 +123,7 @@ int CMT2300A::getRssiDBm()
return CMT2300A_GetRssiDBm(); return CMT2300A_GetRssiDBm();
} }
bool CMT2300A::setPALevel(int8_t level) bool CMT2300A::setPALevel(const int8_t level)
{ {
uint16_t Tx_dBm_word; uint16_t Tx_dBm_word;
switch (level) { switch (level) {

View File

@ -18,7 +18,7 @@ enum FrequencyBand_t {
class CMT2300A { class CMT2300A {
public: public:
CMT2300A(uint8_t pin_sdio, uint8_t pin_clk, uint8_t pin_cs, uint8_t pin_fcs, uint32_t _spi_speed = CMT_SPI_SPEED); CMT2300A(const uint8_t pin_sdio, const uint8_t pin_clk, const uint8_t pin_cs, const uint8_t pin_fcs, const uint32_t _spi_speed = CMT_SPI_SPEED);
bool begin(void); bool begin(void);
@ -62,15 +62,15 @@ public:
* in one call is 32 (for dynamic payload lengths) or whatever number was * in one call is 32 (for dynamic payload lengths) or whatever number was
* previously passed to setPayloadSize() (for static payload lengths). * previously passed to setPayloadSize() (for static payload lengths).
*/ */
void read(void* buf, uint8_t len); void read(void* buf, const uint8_t len);
bool write(const uint8_t* buf, uint8_t len); bool write(const uint8_t* buf, const uint8_t len);
/** /**
* Set RF communication channel. The frequency used by a channel is * Set RF communication channel. The frequency used by a channel is
* @param channel Which RF channel to communicate on, 0-254 * @param channel Which RF channel to communicate on, 0-254
*/ */
void setChannel(uint8_t channel); void setChannel(const uint8_t channel);
/** /**
* Get RF communication channel * Get RF communication channel
@ -90,7 +90,7 @@ public:
int getRssiDBm(); int getRssiDBm();
bool setPALevel(int8_t level); bool setPALevel(const int8_t level);
bool rxFifoAvailable(); bool rxFifoAvailable();

View File

@ -1,142 +1,142 @@
#include "cmt_spi3.h" #include "cmt_spi3.h"
#include <Arduino.h> #include <Arduino.h>
#include <driver/spi_master.h> #include <driver/spi_master.h>
#include <esp_rom_gpio.h> // for esp_rom_gpio_connect_out_signal #include <esp_rom_gpio.h> // for esp_rom_gpio_connect_out_signal
SemaphoreHandle_t paramLock = NULL; SemaphoreHandle_t paramLock = NULL;
#define SPI_PARAM_LOCK() \ #define SPI_PARAM_LOCK() \
do { \ do { \
} while (xSemaphoreTake(paramLock, portMAX_DELAY) != pdPASS) } while (xSemaphoreTake(paramLock, portMAX_DELAY) != pdPASS)
#define SPI_PARAM_UNLOCK() xSemaphoreGive(paramLock) #define SPI_PARAM_UNLOCK() xSemaphoreGive(paramLock)
// for ESP32 this is the so-called HSPI // for ESP32 this is the so-called HSPI
// for ESP32-S2/S3/C3 this nomenclature does not really exist anymore, // for ESP32-S2/S3/C3 this nomenclature does not really exist anymore,
// it is simply the first externally usable hardware SPI master controller // it is simply the first externally usable hardware SPI master controller
#define SPI_CMT SPI2_HOST #define SPI_CMT SPI2_HOST
spi_device_handle_t spi_reg, spi_fifo; spi_device_handle_t spi_reg, spi_fifo;
void cmt_spi3_init(int8_t pin_sdio, int8_t pin_clk, int8_t pin_cs, int8_t pin_fcs, uint32_t spi_speed) void cmt_spi3_init(const int8_t pin_sdio, const int8_t pin_clk, const int8_t pin_cs, const int8_t pin_fcs, const uint32_t spi_speed)
{ {
paramLock = xSemaphoreCreateMutex(); paramLock = xSemaphoreCreateMutex();
spi_bus_config_t buscfg = { spi_bus_config_t buscfg = {
.mosi_io_num = pin_sdio, .mosi_io_num = pin_sdio,
.miso_io_num = -1, // single wire MOSI/MISO .miso_io_num = -1, // single wire MOSI/MISO
.sclk_io_num = pin_clk, .sclk_io_num = pin_clk,
.quadwp_io_num = -1, .quadwp_io_num = -1,
.quadhd_io_num = -1, .quadhd_io_num = -1,
.max_transfer_sz = 32, .max_transfer_sz = 32,
}; };
spi_device_interface_config_t devcfg = { spi_device_interface_config_t devcfg = {
.command_bits = 1, .command_bits = 1,
.address_bits = 7, .address_bits = 7,
.dummy_bits = 0, .dummy_bits = 0,
.mode = 0, // SPI mode 0 .mode = 0, // SPI mode 0
.cs_ena_pretrans = 1, .cs_ena_pretrans = 1,
.cs_ena_posttrans = 1, .cs_ena_posttrans = 1,
.clock_speed_hz = spi_speed, .clock_speed_hz = spi_speed,
.spics_io_num = pin_cs, .spics_io_num = pin_cs,
.flags = SPI_DEVICE_HALFDUPLEX | SPI_DEVICE_3WIRE, .flags = SPI_DEVICE_HALFDUPLEX | SPI_DEVICE_3WIRE,
.queue_size = 1, .queue_size = 1,
.pre_cb = NULL, .pre_cb = NULL,
.post_cb = NULL, .post_cb = NULL,
}; };
ESP_ERROR_CHECK(spi_bus_initialize(SPI_CMT, &buscfg, SPI_DMA_DISABLED)); ESP_ERROR_CHECK(spi_bus_initialize(SPI_CMT, &buscfg, SPI_DMA_DISABLED));
ESP_ERROR_CHECK(spi_bus_add_device(SPI_CMT, &devcfg, &spi_reg)); ESP_ERROR_CHECK(spi_bus_add_device(SPI_CMT, &devcfg, &spi_reg));
// FiFo // FiFo
spi_device_interface_config_t devcfg2 = { spi_device_interface_config_t devcfg2 = {
.command_bits = 0, .command_bits = 0,
.address_bits = 0, .address_bits = 0,
.dummy_bits = 0, .dummy_bits = 0,
.mode = 0, // SPI mode 0 .mode = 0, // SPI mode 0
.cs_ena_pretrans = 2, .cs_ena_pretrans = 2,
.cs_ena_posttrans = (uint8_t)(1 / (spi_speed * 10e6 * 2) + 2), // >2 us .cs_ena_posttrans = (uint8_t)(1 / (spi_speed * 10e6 * 2) + 2), // >2 us
.clock_speed_hz = spi_speed, .clock_speed_hz = spi_speed,
.spics_io_num = pin_fcs, .spics_io_num = pin_fcs,
.flags = SPI_DEVICE_HALFDUPLEX | SPI_DEVICE_3WIRE, .flags = SPI_DEVICE_HALFDUPLEX | SPI_DEVICE_3WIRE,
.queue_size = 1, .queue_size = 1,
.pre_cb = NULL, .pre_cb = NULL,
.post_cb = NULL, .post_cb = NULL,
}; };
ESP_ERROR_CHECK(spi_bus_add_device(SPI_CMT, &devcfg2, &spi_fifo)); ESP_ERROR_CHECK(spi_bus_add_device(SPI_CMT, &devcfg2, &spi_fifo));
esp_rom_gpio_connect_out_signal(pin_sdio, spi_periph_signal[SPI_CMT].spid_out, true, false); esp_rom_gpio_connect_out_signal(pin_sdio, spi_periph_signal[SPI_CMT].spid_out, true, false);
delay(100); delay(100);
} }
void cmt_spi3_write(uint8_t addr, uint8_t dat) void cmt_spi3_write(const uint8_t addr, const uint8_t dat)
{ {
uint8_t tx_data; uint8_t tx_data;
tx_data = ~dat; tx_data = ~dat;
spi_transaction_t t = { spi_transaction_t t = {
.cmd = 1, .cmd = 1,
.addr = ~addr, .addr = ~addr,
.length = 8, .length = 8,
.tx_buffer = &tx_data, .tx_buffer = &tx_data,
.rx_buffer = NULL .rx_buffer = NULL
}; };
SPI_PARAM_LOCK(); SPI_PARAM_LOCK();
ESP_ERROR_CHECK(spi_device_polling_transmit(spi_reg, &t)); ESP_ERROR_CHECK(spi_device_polling_transmit(spi_reg, &t));
SPI_PARAM_UNLOCK(); SPI_PARAM_UNLOCK();
delayMicroseconds(100); delayMicroseconds(100);
} }
uint8_t cmt_spi3_read(uint8_t addr) uint8_t cmt_spi3_read(const uint8_t addr)
{ {
uint8_t rx_data; uint8_t rx_data;
spi_transaction_t t = { spi_transaction_t t = {
.cmd = 0, .cmd = 0,
.addr = ~addr, .addr = ~addr,
.length = 8, .length = 8,
.rxlength = 8, .rxlength = 8,
.tx_buffer = NULL, .tx_buffer = NULL,
.rx_buffer = &rx_data .rx_buffer = &rx_data
}; };
SPI_PARAM_LOCK(); SPI_PARAM_LOCK();
ESP_ERROR_CHECK(spi_device_polling_transmit(spi_reg, &t)); ESP_ERROR_CHECK(spi_device_polling_transmit(spi_reg, &t));
SPI_PARAM_UNLOCK(); SPI_PARAM_UNLOCK();
delayMicroseconds(100); delayMicroseconds(100);
return rx_data; return rx_data;
} }
void cmt_spi3_write_fifo(const uint8_t* buf, uint16_t len) void cmt_spi3_write_fifo(const uint8_t* buf, const uint16_t len)
{ {
uint8_t tx_data; uint8_t tx_data;
spi_transaction_t t = { spi_transaction_t t = {
.length = 8, .length = 8,
.tx_buffer = &tx_data, // reference to write data .tx_buffer = &tx_data, // reference to write data
.rx_buffer = NULL .rx_buffer = NULL
}; };
SPI_PARAM_LOCK(); SPI_PARAM_LOCK();
for (uint8_t i = 0; i < len; i++) { for (uint8_t i = 0; i < len; i++) {
tx_data = ~buf[i]; // negate buffer contents tx_data = ~buf[i]; // negate buffer contents
ESP_ERROR_CHECK(spi_device_polling_transmit(spi_fifo, &t)); ESP_ERROR_CHECK(spi_device_polling_transmit(spi_fifo, &t));
delayMicroseconds(4); // > 4 us delayMicroseconds(4); // > 4 us
} }
SPI_PARAM_UNLOCK(); SPI_PARAM_UNLOCK();
} }
void cmt_spi3_read_fifo(uint8_t* buf, uint16_t len) void cmt_spi3_read_fifo(uint8_t* buf, const uint16_t len)
{ {
uint8_t rx_data; uint8_t rx_data;
spi_transaction_t t = { spi_transaction_t t = {
.length = 8, .length = 8,
.rxlength = 8, .rxlength = 8,
.tx_buffer = NULL, .tx_buffer = NULL,
.rx_buffer = &rx_data .rx_buffer = &rx_data
}; };
SPI_PARAM_LOCK(); SPI_PARAM_LOCK();
for (uint8_t i = 0; i < len; i++) { for (uint8_t i = 0; i < len; i++) {
ESP_ERROR_CHECK(spi_device_polling_transmit(spi_fifo, &t)); ESP_ERROR_CHECK(spi_device_polling_transmit(spi_fifo, &t));
delayMicroseconds(4); // > 4 us delayMicroseconds(4); // > 4 us
buf[i] = rx_data; buf[i] = rx_data;
} }
SPI_PARAM_UNLOCK(); SPI_PARAM_UNLOCK();
} }

View File

@ -1,14 +1,14 @@
#ifndef __CMT_SPI3_H #ifndef __CMT_SPI3_H
#define __CMT_SPI3_H #define __CMT_SPI3_H
#include <stdint.h> #include <stdint.h>
void cmt_spi3_init(int8_t pin_sdio, int8_t pin_clk, int8_t pin_cs, int8_t pin_fcs, uint32_t spi_speed); void cmt_spi3_init(const int8_t pin_sdio, const int8_t pin_clk, const int8_t pin_cs, const int8_t pin_fcs, const uint32_t spi_speed);
void cmt_spi3_write(uint8_t addr, uint8_t dat); void cmt_spi3_write(const uint8_t addr, const uint8_t dat);
uint8_t cmt_spi3_read(uint8_t addr); uint8_t cmt_spi3_read(const uint8_t addr);
void cmt_spi3_write_fifo(const uint8_t* p_buf, uint16_t len); void cmt_spi3_write_fifo(const uint8_t* p_buf, const uint16_t len);
void cmt_spi3_read_fifo(uint8_t* p_buf, uint16_t len); void cmt_spi3_read_fifo(uint8_t* p_buf, const uint16_t len);
#endif #endif

View File

@ -52,7 +52,7 @@ uint8_t HoymilesRadio_CMT::getChannelFromFrequency(const uint32_t frequency) con
return (frequency - _radio->getBaseFrequency()) / getChannelWidth(); // frequency to channel return (frequency - _radio->getBaseFrequency()) / getChannelWidth(); // frequency to channel
} }
std::vector<CountryFrequencyList_t> HoymilesRadio_CMT::getCountryFrequencyList() std::vector<CountryFrequencyList_t> HoymilesRadio_CMT::getCountryFrequencyList() const
{ {
std::vector<CountryFrequencyList_t> v; std::vector<CountryFrequencyList_t> v;
for (const auto& [key, value] : countryDefinition) { for (const auto& [key, value] : countryDefinition) {
@ -237,7 +237,7 @@ CountryModeId_t HoymilesRadio_CMT::getCountryMode() const
return _countryMode; return _countryMode;
} }
void HoymilesRadio_CMT::setCountryMode(CountryModeId_t mode) void HoymilesRadio_CMT::setCountryMode(const CountryModeId_t mode)
{ {
_radio->setFrequencyBand(countryDefinition.at(mode).Band); _radio->setFrequencyBand(countryDefinition.at(mode).Band);
_countryMode = mode; _countryMode = mode;

View File

@ -57,14 +57,14 @@ public:
} }
CountryModeId_t getCountryMode() const; CountryModeId_t getCountryMode() const;
void setCountryMode(CountryModeId_t mode); void setCountryMode(const CountryModeId_t mode);
uint32_t getInvBootFrequency() const; uint32_t getInvBootFrequency() const;
uint32_t getFrequencyFromChannel(const uint8_t channel) const; uint32_t getFrequencyFromChannel(const uint8_t channel) const;
uint8_t getChannelFromFrequency(const uint32_t frequency) const; uint8_t getChannelFromFrequency(const uint32_t frequency) const;
std::vector<CountryFrequencyList_t> getCountryFrequencyList(); std::vector<CountryFrequencyList_t> getCountryFrequencyList() const;
private: private:
void ARDUINO_ISR_ATTR handleInt1(); void ARDUINO_ISR_ATTR handleInt1();