diff --git a/src/Catena.h b/src/Catena.h index 6cb10ce..b695ea6 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_4917) +# include "Catena4917.h" +# define CATENA_H_SUPER_ McciCatena::Catena4917 /* fallback in case it's SAMD but not what we expect */ #elif defined(ARDUINO_ARCH_SAMD) # include "CatenaSamd21.h" diff --git a/src/Catena4917.h b/src/Catena4917.h new file mode 100644 index 0000000..01a781f --- /dev/null +++ b/src/Catena4917.h @@ -0,0 +1,63 @@ +/* + +Module: Catena4917.h + +Function: + class Catena4917: CatenaBase Platform to represent a Catena 4917 + +Copyright notice: + See accompanying LICENSE file. + +Author: + Pranau R, MCCI Corporation November 2022 + +*/ + +#ifndef _Catena4917_H_ /* prevent multiple includes */ +#define _Catena4917_H_ + +#pragma once + +#ifndef _CATENA491x_H_ +# include "Catena491x.h" +#endif + +namespace McciCatena { + +class Catena4917 : public Catena491x + { +public: + using Super = Catena4917; + + // no specific constructor. + Catena4917() {}; + + // uses default destructor + + // neither copyable nor movable + Catena4917(const Catena4917&) = delete; + Catena4917& operator=(const Catena4917&) = delete; + Catena4917(const Catena4917&&) = delete; + Catena4917& operator=(const Catena4917&&) = delete; + + virtual const char *CatenaName() const override { return "Catena 4917"; }; + 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 Catena4917.h ****/ +#endif /* _Catena4917_H_ */ \ No newline at end of file diff --git a/src/Catena491x.h b/src/Catena491x.h new file mode 100644 index 0000000..995351b --- /dev/null +++ b/src/Catena491x.h @@ -0,0 +1,106 @@ +/* + +Module: Catena491x.h + +Function: + class Catena491x: CatenaBase Platform to represent a Catena 491x + (such as the 4917). + +Copyright notice: + See accompanying LICENSE file. + +Author: + Pranau R, 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 = A3, + APIN_VBUS_SENSE = A4, + }; + + enum ANALOG_CHANNELS + { + ANALOG_CHANNEL_A0 = 0, + ANALOG_CHANNEL_A1 = 5, + ANALOG_CHANNEL_A2 = 4, + ANALOG_CHANNEL_A3 = 3, + ANALOG_CHANNEL_A4 = 2, + ANALOG_CHANNEL_VBAT = ANALOG_CHANNEL_A3, + ANALOG_CHANNEL_VBUS = ANALOG_CHANNEL_A4, + 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..e7db209 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 LTR329 Lux sensor + fHasLuxLtr329 = 1 << 22, + //platform has LIS2HH12 Accelerometer + fHasLIS2HH12 = 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..0948033 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) +// {d9d35ffd-1859-4686-900c-dd7fd5941886} +#define GUID_HW_CATENA_4917_BASE(f) \ + MCCIADK_GUID_GEN_INIT(f, 0xd9d35ffd, 0x1859, 0x4686, 0x90, 0x0c, 0xdd, 0x7f, 0xd5, 0x94, 0x18, 0x86) + /**** end of catena_guids.h ****/ #endif /* _CATENA_GUIDS_H_ */ diff --git a/src/Catena_Platforms.h b/src/Catena_Platforms.h index b641f61..1ebbee5 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 gkPlatformCatena4917; + } /* namespace McciCatena */ /**** end of Catena_Platforms.h ****/ diff --git a/src/lib/stm32/catena491x/Catena4917_ReadVoltage.cpp b/src/lib/stm32/catena491x/Catena4917_ReadVoltage.cpp new file mode 100644 index 0000000..6b2eb75 --- /dev/null +++ b/src/lib/stm32/catena491x/Catena4917_ReadVoltage.cpp @@ -0,0 +1,81 @@ +/* + +Module: Catena4917_ReadVoltage.cpp + +Function: + Catena4917::ReadVbat() and Catena4917::ReadVbus() + +Copyright notice: + See accompanying LICENSE file. + +Author: + Pranau R, MCCI Corporation November 2022 + +*/ + +#ifdef ARDUINO_ARCH_STM32 + +#include "Catena4917.h" +#include "Catena_Log.h" + +#include +using namespace McciCatena; + +/****************************************************************************\ +| +| Manifest constants & typedefs. +| +\****************************************************************************/ + + + +/****************************************************************************\ +| +| Read-only data. +| +\****************************************************************************/ + + + +/****************************************************************************\ +| +| Variables. +| +\****************************************************************************/ + +float +Catena4917::ReadVbat(void) const + { + float volt = this->ReadAnalog(Catena491x::ANALOG_CHANNEL_VBAT, 1, 1); + return volt / 1000; + } + +float +Catena4917::ReadVbus(void) const + { + float volt = this->ReadAnalog(Catena491x::ANALOG_CHANNEL_VBUS, 6, 3); + return volt / 1000; + } + +#if defined(ARDUINO_MCCI_MODEL_4917) && defined(USBD_LL_ConnectionState_WEAK) + +extern "C" { + +uint32_t USBD_LL_ConnectionState(void) + { + uint32_t vBus; + bool fStatus; + + fStatus = CatenaStm32L0_ReadAnalog( + Catena491x::ANALOG_CHANNEL_VBUS, 6, 3, &vBus + ); + return (fStatus && vBus < 3000) ? 0 : 1; + } + +} + +#endif // ARDUINO_MCCI_MODEL_4917 + +#endif // ARDUINO_ARCH_STM32 + +/**** end of Catena4917_ReadVoltage.cpp ****/ \ No newline at end of file diff --git a/src/lib/stm32/catena491x/Catena4917_getPlatformTable.cpp b/src/lib/stm32/catena491x/Catena4917_getPlatformTable.cpp new file mode 100644 index 0000000..9538bcc --- /dev/null +++ b/src/lib/stm32/catena491x/Catena4917_getPlatformTable.cpp @@ -0,0 +1,90 @@ +/* + +Module: Catena4917_getPlatformTable.cpp + +Function: + Catena4917::getPlatformTable() + +Copyright notice: + See accompanying LICENSE file. + +Author: + Pranau R, MCCI Corporation November 2022 + +*/ + +#ifdef ARDUINO_ARCH_STM32 + +#include "Catena4917.h" + +#include "Catena_Log.h" +#include "Catena_Platforms.h" +#include "Catena_Guids.h" + +/****************************************************************************\ +| +| Read-only data. +| +\****************************************************************************/ + +namespace McciCatena { + +const CATENA_PLATFORM gkPlatformCatena4917 = + { + Guid: GUID_HW_CATENA_4917_BASE(WIRE), + pParent: &gkPlatformCatena4917, + PlatformFlags: + CatenaBase::fHasLoRa | + CatenaBase::fHasTtnNycLoRa | + CatenaBase::fHasLIS2HH12 | + CatenaBase::fHasFRAM | + CatenaBase::fHasFlash + }; + +const CATENA_PLATFORM (* const Catena4917::vPlatforms[]) = + { + // entry 0 is the default + &gkPlatformCatena4917, + }; + +const size_t Catena4917::nvPlatforms = sizeof(Catena4917::vPlatforms) / sizeof(Catena4917::vPlatforms[0]); + +/* + +Name: Catena4917::getPlatformTable() + +Function: + Get the known platform table. + +Definition: + public: virtual + void Catena4917::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 +Catena4917::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