Skip to content

Commit

Permalink
Add BUS based IO (busio) support (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
jetpax authored Feb 15, 2025
1 parent dbf2704 commit 3b4c91f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 5 deletions.
31 changes: 26 additions & 5 deletions include/digio.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,15 @@
#ifndef DIGIO_H_INCLUDED
#define DIGIO_H_INCLUDED


#include <libopencm3/stm32/gpio.h>
#include "digio_prj.h"

#if __has_include("busio.h")
#include "busio.h"
#define BUSIO_ENABLED
#endif

namespace PinMode {
enum PinMode
{
Expand All @@ -39,12 +45,22 @@ namespace PinMode {
};
}


class DigIo
{
public:
#define DIG_IO_ENTRY(name, port, pin, mode) static DigIo name;
DIG_IO_LIST
#undef DIG_IO_ENTRY
#define DIG_IO_ENTRY(name, port, pin, mode) static DigIo name;

#ifdef BUSIO_ENABLED
#define BUS_IO_ENTRY(name, type, channel, mode) static BusIo name;
#endif

DIG_IO_LIST // expands all real & MCP pins into static members
#undef DIG_IO_ENTRY

#ifdef BUSIO_ENABLED
#undef BUS_IO_ENTRY
#endif

/** Map GPIO pin object to hardware pin.
* @param[in] port port to use for this pin
Expand All @@ -54,7 +70,6 @@ class DigIo
*/
void Configure(uint32_t port, uint16_t pin, PinMode::PinMode pinMode);


/**
* Get pin value
*
Expand Down Expand Up @@ -89,8 +104,14 @@ class DigIo
uint16_t _pin;
bool _invert;
};
//Configure all digio objects from the given list

//Configure all digio and (optionally busio) objects from the given list
#define DIG_IO_ENTRY(name, port, pin, mode) DigIo::name.Configure(port, pin, mode);

#ifdef BUSIO_ENABLED
#define BUS_IO_ENTRY(name, busType, channel, mode) DigIo::name.Configure(busType, channel, mode);
#endif

#define DIG_IO_CONFIGURE(l) l

#endif // DIGIO_H_INCLUDED
6 changes: 6 additions & 0 deletions src/digio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@

#undef DIG_IO_ENTRY
#define DIG_IO_ENTRY(name, port, pin, mode) DigIo DigIo::name;

#ifdef BUSIO_ENABLED
#undef BUS_IO_ENTRY
#define BUS_IO_ENTRY(name, busType, channel, mode) BusIo DigIo::name;
#endif

DIG_IO_LIST

void DigIo::Configure(uint32_t port, uint16_t pin, PinMode::PinMode pinMode)
Expand Down

0 comments on commit 3b4c91f

Please sign in to comment.