diff --git a/src/Catena.h b/src/Catena.h index 6cb10ce..980e567 100644 --- a/src/Catena.h +++ b/src/Catena.h @@ -64,6 +64,9 @@ Copyright notice: #elif defined(ARDUINO_MCCI_CATENA_4802) # include "Catena4802.h" # define CATENA_H_SUPER_ McciCatena::Catena4802 +#elif defined(ARDUINO_MCCI_MODEL_4916) || defined(ARDUINO_MODEL_4916) +# include "Catena4916.h" +# define CATENA_H_SUPER_ McciCatena::Catena4916 /* fallback in case it's SAMD but not what we expect */ #elif defined(ARDUINO_ARCH_SAMD) # include "CatenaSamd21.h" diff --git a/src/Catena4916.h b/src/Catena4916.h new file mode 100644 index 0000000..093233f --- /dev/null +++ b/src/Catena4916.h @@ -0,0 +1,63 @@ +/* + +Module: Catena4916.h + +Function: + class Catena4916: CatenaBase Platform to represent a Catena 4916 + +Copyright notice: + See accompanying LICENSE file. + +Author: + Dhinesh Kumar Pitchai, MCCI Corporation November 2022 + +*/ + +#ifndef _Catena4916_H_ /* prevent multiple includes */ +#define _Catena4916_H_ + +#pragma once + +#ifndef _CATENA491x_H_ +# include "Catena491x.h" +#endif + +namespace McciCatena { + +class Catena4916 : public Catena491x + { +public: + using Super = Catena4916; + + // no specific constructor. + Catena4916() {}; + + // uses default destructor + + // neither copyable nor movable + Catena4916(const Catena4916&) = delete; + Catena4916& operator=(const Catena4916&) = delete; + Catena4916(const Catena4916&&) = delete; + Catena4916& operator=(const Catena4916&&) = delete; + + virtual const char *CatenaName() const override { return "Catena 4916"; }; + virtual float ReadVbat(void) const override; + virtual float ReadVbus(void) const override; + +protected: + // we are required to provide a table of platforms + virtual void getPlatformTable( + const CATENA_PLATFORM * const * &vPlatforms, + size_t &nvPlatforms + ) override; + +private: + // the known platforms + static const CATENA_PLATFORM(* const vPlatforms[]); + static const size_t nvPlatforms; + }; + +} // namespace McciCatena + +/**** end of Catena4916.h ****/ +#endif /* _Catena4916_H_ */ \ No newline at end of file diff --git a/src/Catena491x.h b/src/Catena491x.h new file mode 100644 index 0000000..983a226 --- /dev/null +++ b/src/Catena491x.h @@ -0,0 +1,104 @@ +/* + +Module: Catena491x.h + +Function: + class Catena491x: CatenaBase Platform to represent a Catena 491x + (such as the 4916). + +Copyright notice: + See accompanying LICENSE file. + +Author: + Dhinesh Kumar Pitchai, MCCI Corporation November 2022 + +*/ + +#ifndef _CATENA491X_H_ /* prevent multiple includes */ +#define _CATENA491X_H_ + +#pragma once + +#ifndef _CATENASTM32L0_H_ +# include "CatenaStm32L0.h" +#endif + +namespace McciCatena { + +class Catena491x : public CatenaStm32L0 + { +public: + using Super = CatenaStm32L0; + + // no specific constructor. + Catena491x() {}; + + // uses default destructor + + // neither copyable nor movable + Catena491x(const Catena491x&) = delete; + Catena491x& operator=(const Catena491x&) = delete; + Catena491x(const Catena491x&&) = delete; + Catena491x& operator=(const Catena491x&&) = delete; + + // LoRaWAN binding + class LoRaWAN /* forward */; + + enum ANALOG_PINS + { + APIN_VBAT_SENSE = A1, + // APIN_VBUS_SENSE = A4, + }; + + enum ANALOG_CHANNELS + { + ANALOG_CHANNEL_A1 = 5, + ANALOG_CHANNEL_A2 = 4, + ANALOG_CHANNEL_A3 = 3, + ANALOG_CHANNEL_A4 = 2, + ANALOG_CHANNEL_VBAT = ANALOG_CHANNEL_A1, + ANALOG_CHANNEL_VREF = 17, + }; + + enum DIGITAL_PINS + { + PIN_STATUS_LED = D13, + PIN_SPI2_FLASH_SS = D19, + PIN_SPI2_MOSI = D23, + PIN_SPI2_MISO = D22, + PIN_SPI2_SCK = D24, + }; + + // methods + virtual bool begin() override; + +protected: + +private: + }; + +/* +|| The LoRaWAN class for the Catena 455x. Assumes The Things Network +*/ +class Catena491x::LoRaWAN : public CatenaStm32L0::LoRaWAN + { +public: + using Super = CatenaStm32L0::LoRaWAN; + + /* + || the constructor. We don't do anything at this level, the + || Super constructor does most of the work. + */ + LoRaWAN() {}; + + bool begin(Catena491x *pParent); + +protected: + +private: + }; + +} // namespace McciCatena + +/**** end of Catena491x.h ****/ +#endif /* _CATENA491X_H_ */ \ No newline at end of file diff --git a/src/CatenaBase.h b/src/CatenaBase.h index d53120a..a6d996e 100644 --- a/src/CatenaBase.h +++ b/src/CatenaBase.h @@ -210,6 +210,10 @@ class CatenaBase fHasSHT3x = 1 << 20, //platform has I2C Level Shifter fHasI2cLevelShifter = 1 << 21, + //platform has GPS SAM-M8Q + fHasSAMM8Q = 1 << 22, + //platform has ADS131M04 + fHasADS131M04 = 1 << 23, // special wiring variants all are offsets from M100... // we support up to 127 variants, becuase we have 7 diff --git a/src/Catena_Guids.h b/src/Catena_Guids.h index 30f6d1a..84f27ea 100644 --- a/src/Catena_Guids.h +++ b/src/Catena_Guids.h @@ -233,5 +233,9 @@ Copyright notice: #define GUID_HW_CATENA_4802_BASE(f) \ MCCIADK_GUID_GEN_INIT(f, 0xdaaf345e, 0xb5d5, 0x4a32, 0xa3, 0x03, 0x3a, 0xc7, 0x0b, 0x81, 0xd2, 0x60) +// {2eadd9eb-80e3-4e14-99c6-851f036ffa8d} +#define GUID_HW_CATENA_4916_BASE(f) \ + MCCIADK_GUID_GEN_INIT(f, 0x2eadd9eb, 0x80e3, 0x4e14, 0x99, 0xc6, 0x85, 0x1f, 0x03, 0x6f, 0xfa, 0x8d) + /**** end of catena_guids.h ****/ #endif /* _CATENA_GUIDS_H_ */ diff --git a/src/Catena_Platforms.h b/src/Catena_Platforms.h index b641f61..6da0915 100644 --- a/src/Catena_Platforms.h +++ b/src/Catena_Platforms.h @@ -79,6 +79,8 @@ extern const CATENA_PLATFORM gkPlatformCatena4630; extern const CATENA_PLATFORM gkPlatformCatena4801; extern const CATENA_PLATFORM gkPlatformCatena4802; +extern const CATENA_PLATFORM gkPlatformCatena4916; + } /* namespace McciCatena */ /**** end of Catena_Platforms.h ****/ diff --git a/src/lib/stm32/catena491x/Catena4916_ReadVoltage.cpp b/src/lib/stm32/catena491x/Catena4916_ReadVoltage.cpp new file mode 100644 index 0000000..2df335d --- /dev/null +++ b/src/lib/stm32/catena491x/Catena4916_ReadVoltage.cpp @@ -0,0 +1,61 @@ +/* + +Module: Catena4916_ReadVoltage.cpp + +Function: + Catena4916::ReadVbat() and Catena4916::ReadVbus() + +Copyright notice: + See accompanying LICENSE file. + +Author: + Pranau R, MCCI Corporation November 2022 + +*/ + +#ifdef ARDUINO_ARCH_STM32 + +#include "Catena4916.h" +#include "Catena_Log.h" + +#include +using namespace McciCatena; + +/****************************************************************************\ +| +| Manifest constants & typedefs. +| +\****************************************************************************/ + + + +/****************************************************************************\ +| +| Read-only data. +| +\****************************************************************************/ + + + +/****************************************************************************\ +| +| Variables. +| +\****************************************************************************/ + +float +Catena4916::ReadVbat(void) const + { + float volt = this->ReadAnalog(Catena491x::ANALOG_CHANNEL_VBAT, 1, 2); + return volt / 1000; + } + +float +Catena4916::ReadVbus(void) const + { + return 0; + } + +#endif // ARDUINO_ARCH_STM32 + +/**** end of Catena4916_ReadVoltage.cpp ****/ \ No newline at end of file diff --git a/src/lib/stm32/catena491x/Catena4916_getPlatformTable.cpp b/src/lib/stm32/catena491x/Catena4916_getPlatformTable.cpp new file mode 100644 index 0000000..b8bcd65 --- /dev/null +++ b/src/lib/stm32/catena491x/Catena4916_getPlatformTable.cpp @@ -0,0 +1,93 @@ +/* + +Module: Catena4916_getPlatformTable.cpp + +Function: + Catena4916::getPlatformTable() + +Copyright notice: + See accompanying LICENSE file. + +Author: + Pranau R, MCCI Corporation November 2022 + +*/ + +#ifdef ARDUINO_ARCH_STM32 + +#include "Catena4916.h" + +#include "Catena_Log.h" +#include "Catena_Platforms.h" +#include "Catena_Guids.h" + +/****************************************************************************\ +| +| Read-only data. +| +\****************************************************************************/ + +namespace McciCatena { + +const CATENA_PLATFORM gkPlatformCatena4916 = + { + Guid: GUID_HW_CATENA_4916_BASE(WIRE), + pParent: &gkPlatformCatena4916, + PlatformFlags: + CatenaBase::fHasLoRa | + CatenaBase::fHasTtnNycLoRa | + CatenaBase::fHasSHT3x | + CatenaBase::fHasBme680 | + CatenaBase::fHasADS131M04 | + CatenaBase::fHasSAMM8Q | + CatenaBase::fHasFRAM | + CatenaBase::fHasFlash + }; + +const CATENA_PLATFORM (* const Catena4916::vPlatforms[]) = + { + // entry 0 is the default + &gkPlatformCatena4916, + }; + +const size_t Catena4916::nvPlatforms = sizeof(Catena4916::vPlatforms) / sizeof(Catena4916::vPlatforms[0]); + +/* + +Name: Catena4916::getPlatformTable() + +Function: + Get the known platform table. + +Definition: + public: virtual + void Catena4916::getPlatformTable( + const CATENA_PLATFORM * const * &vPlatforms, + size_t &nvPlatforms + ) override; + +Description: + This override for getPlatformTable() returns the vector of platform + GUIDs for this Catena. + +Returns: + vPlatforms is set to the base of the array of pointers to platform + stuctures; and nvPlatforms is set to the number of entries in + the table. + +*/ + +/* public virtual override */ +void +Catena4916::getPlatformTable( + const CATENA_PLATFORM * const * &result_vPlatforms, + size_t &result_nvPlatforms + ) + { + result_vPlatforms = vPlatforms; + result_nvPlatforms = nvPlatforms; + } + +} /* namespace McciCatena */ + +#endif // ARDUINO_ARCH_STM32 diff --git a/src/lib/stm32/catena491x/Catena491x_LoRaWAN_begin.cpp b/src/lib/stm32/catena491x/Catena491x_LoRaWAN_begin.cpp new file mode 100644 index 0000000..891815e --- /dev/null +++ b/src/lib/stm32/catena491x/Catena491x_LoRaWAN_begin.cpp @@ -0,0 +1,68 @@ +/* + +Module: Catena491x_LoRaWAN_begin.cpp + +Function: + Catena491x::LoRaWAN::begin() + +Copyright notice: + See accompanying LICENSE file. + +Author: + Pranau R, MCCI Corporation November 2022 + +*/ + +#ifdef ARDUINO_ARCH_STM32 + +#include "Catena491x.h" + +#include "Catena_Log.h" +#include "mcciadk_baselib.h" + +using namespace McciCatena; + +/* + +Name: Catena491x::LoRaWAN::begin() + +Function: + Record linkage to main Catena object and set up LoRaWAN. + +Definition: + bool Catena491x::LoRaWAN::begin( + Catena491x *pParent + ); + +Description: + We record parent pointers, and other useful things for later. + +Returns: + true for success, false for failure. + +*/ + +bool +Catena491x::LoRaWAN::begin( + Catena491x *pParent + ) + { + gLog.printf(gLog.kTrace, "+Catena491x::LoRaWAN::begin()\n"); + + /* call the base begin */ + if (! this->Super::begin(pParent)) + { + gLog.printf( + gLog.kBug, + "?Catena491x::LoRaWAN::begin: Super::begin() failed\n" + ); + return false; + } + + /* indicate success to the client */ + return true; + } + +#endif // ARDUINO_ARCH_STM32 + +/**** end of Catena491x_LoRaWAN_begin.cpp ****/ \ No newline at end of file diff --git a/src/lib/stm32/catena491x/Catena491x_begin.cpp b/src/lib/stm32/catena491x/Catena491x_begin.cpp new file mode 100644 index 0000000..c21dedb --- /dev/null +++ b/src/lib/stm32/catena491x/Catena491x_begin.cpp @@ -0,0 +1,63 @@ +/* + +Module: Catena491x_begin.cpp + +Function: + Catena491x::begin(). + +Copyright notice: + See accompanying LICENSE file. + +Author: + Pranau R, MCCI Corporation November 2022 + +*/ + +#ifdef ARDUINO_ARCH_STM32 + +#include "Catena491x.h" + +#include "Catena_Log.h" + +using namespace McciCatena; + +/* + +Name: Catena491x::begin() + +Function: + Set up all the well-known board peripherals. + +Definition: + bool Catena491x::begin(); + +Description: + Issues begin() for all the Catena491x things. + +Returns: + true for success, false for failure. + +*/ + +bool Catena491x::begin() + { + Serial.begin(115200); + Wire.begin(); + delay(1000); + gLog.begin(cLog::DebugFlags(gLog.kError | gLog.kBug)); + gLog.printf( + gLog.kTrace, + "\n+Catena491x::begin() for %s\n", + CatenaName() + ); + + // do the platform selection. + if (! this->Super::begin()) + return false; + + return true; + } + +#endif // ARDUINO_ARCH_STM32 + +/**** end of Catena491x_begin.cpp ****/ \ No newline at end of file