Skip to content

Commit

Permalink
fix #344: add platform support for model4917
Browse files Browse the repository at this point in the history
  • Loading branch information
dhineshkumarmcci committed Nov 24, 2022
1 parent 17a7ecc commit 002e52a
Show file tree
Hide file tree
Showing 10 changed files with 484 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/Catena.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
63 changes: 63 additions & 0 deletions src/Catena4917.h
Original file line number Diff line number Diff line change
@@ -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_ */
106 changes: 106 additions & 0 deletions src/Catena491x.h
Original file line number Diff line number Diff line change
@@ -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_ */
4 changes: 4 additions & 0 deletions src/CatenaBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions src/Catena_Guids.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_ */
2 changes: 2 additions & 0 deletions src/Catena_Platforms.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 ****/
Expand Down
81 changes: 81 additions & 0 deletions src/lib/stm32/catena491x/Catena4917_ReadVoltage.cpp
Original file line number Diff line number Diff line change
@@ -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 <Arduino.h>
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 ****/
90 changes: 90 additions & 0 deletions src/lib/stm32/catena491x/Catena4917_getPlatformTable.cpp
Original file line number Diff line number Diff line change
@@ -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
Loading

0 comments on commit 002e52a

Please sign in to comment.