clang-format the lot

This commit is contained in:
Phillip Burgess 2020-04-30 15:30:24 -07:00
parent 40cb6a9cac
commit a51676db5e
5 changed files with 1564 additions and 1515 deletions

View file

@ -64,41 +64,41 @@ extern Protomatter_core *_PM_protoPtr; ///< In core.c (via arch.h)
// arch.h) because it's not architecture-specific. // arch.h) because it's not architecture-specific.
#define _PM_ROW_DELAY 8 ///< Delay time between row address line changes (ms) #define _PM_ROW_DELAY 8 ///< Delay time between row address line changes (ms)
Adafruit_Protomatter::Adafruit_Protomatter(uint16_t bitWidth, uint8_t bitDepth,
uint8_t rgbCount, uint8_t *rgbList,
uint8_t addrCount, uint8_t *addrList,
uint8_t clockPin, uint8_t latchPin,
uint8_t oePin, bool doubleBuffer,
void *timer)
: GFXcanvas16(bitWidth, (2 << min(addrCount, 5)) * min(rgbCount, 5)) {
if (bitDepth > 6)
bitDepth = 6; // GFXcanvas16 color limit (565)
Adafruit_Protomatter::Adafruit_Protomatter( // Arguments are passed through to the C _PM_init() function which does
uint16_t bitWidth, uint8_t bitDepth, // some input validation and minor allocation. Return value is ignored
uint8_t rgbCount, uint8_t *rgbList, // because we can't really do anything about it in a C++ constructor.
uint8_t addrCount, uint8_t *addrList, // The class begin() function checks rgbPins for NULL to determine
uint8_t clockPin, uint8_t latchPin, uint8_t oePin, // whether to proceed or indicate an error.
bool doubleBuffer, void *timer) : (void)_PM_init(&core, bitWidth, bitDepth, rgbCount, rgbList, addrCount,
GFXcanvas16(bitWidth, (2 << min(addrCount, 5)) * min(rgbCount, 5)) { addrList, clockPin, latchPin, oePin, doubleBuffer, timer);
if(bitDepth > 6) bitDepth = 6; // GFXcanvas16 color limit (565)
// Arguments are passed through to the C _PM_init() function which does
// some input validation and minor allocation. Return value is ignored
// because we can't really do anything about it in a C++ constructor.
// The class begin() function checks rgbPins for NULL to determine
// whether to proceed or indicate an error.
(void)_PM_init(&core, bitWidth, bitDepth, rgbCount, rgbList,
addrCount, addrList, clockPin, latchPin, oePin, doubleBuffer, timer);
} }
Adafruit_Protomatter::~Adafruit_Protomatter(void) { Adafruit_Protomatter::~Adafruit_Protomatter(void) {
_PM_free(&core); _PM_free(&core);
_PM_protoPtr = NULL; _PM_protoPtr = NULL;
} }
ProtomatterStatus Adafruit_Protomatter::begin(void) { ProtomatterStatus Adafruit_Protomatter::begin(void) {
_PM_protoPtr = &core; _PM_protoPtr = &core;
return _PM_begin(&core); return _PM_begin(&core);
} }
// Transfer data from GFXcanvas16 to the matrix framebuffer's weird // Transfer data from GFXcanvas16 to the matrix framebuffer's weird
// internal format. The actual conversion functions referenced below // internal format. The actual conversion functions referenced below
// are in core.c, reasoning is explained there. // are in core.c, reasoning is explained there.
void Adafruit_Protomatter::show(void) { void Adafruit_Protomatter::show(void) {
_PM_convert_565(&core, getBuffer(), WIDTH); _PM_convert_565(&core, getBuffer(), WIDTH);
_PM_swapbuffer_maybe(&core); _PM_swapbuffer_maybe(&core);
} }
// Returns current value of frame counter and resets its value to zero. // Returns current value of frame counter and resets its value to zero.
@ -106,5 +106,5 @@ void Adafruit_Protomatter::show(void) {
// intervals), can be used to get a rough frames-per-second value for // intervals), can be used to get a rough frames-per-second value for
// the matrix (since this is difficult to estimate beforehand). // the matrix (since this is difficult to estimate beforehand).
uint32_t Adafruit_Protomatter::getFrameCount(void) { uint32_t Adafruit_Protomatter::getFrameCount(void) {
return _PM_getFrameCount(_PM_protoPtr); return _PM_getFrameCount(_PM_protoPtr);
} }

View file

@ -13,93 +13,93 @@
the drawing operations. the drawing operations.
*/ */
class Adafruit_Protomatter : public GFXcanvas16 { class Adafruit_Protomatter : public GFXcanvas16 {
public: public:
/*! /*!
@brief Adafruit_Protomatter constructor. @brief Adafruit_Protomatter constructor.
@param bitWidth Total width of RGB matrix chain, in pixels. @param bitWidth Total width of RGB matrix chain, in pixels.
Usu. some multiple of 32, but maybe exceptions. Usu. some multiple of 32, but maybe exceptions.
@param bitDepth Color "depth" in bitplanes, determines range of @param bitDepth Color "depth" in bitplanes, determines range of
shades of red, green and blue. e.g. passing 4 shades of red, green and blue. e.g. passing 4
bits = 16 shades ea. R,G,B = 16x16x16 = 4096 bits = 16 shades ea. R,G,B = 16x16x16 = 4096
colors. Max is 6, since the GFX library works colors. Max is 6, since the GFX library works
with "565" RGB colors (6 bits green, 5 red/blue). with "565" RGB colors (6 bits green, 5 red/blue).
@param rgbCount Number of "sets" of RGB data pins, each set @param rgbCount Number of "sets" of RGB data pins, each set
containing 6 pins (2 ea. R,G,B). Typically 1, containing 6 pins (2 ea. R,G,B). Typically 1,
indicating a single matrix (or matrix chain). indicating a single matrix (or matrix chain).
In theory (but not yet extensively tested), In theory (but not yet extensively tested),
multiple sets of pins can be driven in parallel, multiple sets of pins can be driven in parallel,
up to 5 on some devices (if the hardware design up to 5 on some devices (if the hardware design
provides all those bits on one PORT). provides all those bits on one PORT).
@param rgbList A uint8_t array of pins (Arduino pin numbering), @param rgbList A uint8_t array of pins (Arduino pin numbering),
6X the prior rgbCount value, corresponding to 6X the prior rgbCount value, corresponding to
the 6 output color bits for a matrix (or chain). the 6 output color bits for a matrix (or chain).
Order is upper-half red, green, blue, lower-half Order is upper-half red, green, blue, lower-half
red, green blue (repeat for each add'l chain). red, green blue (repeat for each add'l chain).
All the RGB pins (plus the clock pin below on All the RGB pins (plus the clock pin below on
some architectures) MUST be on the same PORT some architectures) MUST be on the same PORT
register. It's recommended (but not required) register. It's recommended (but not required)
that all RGB pins (and clock depending on arch) that all RGB pins (and clock depending on arch)
be within the same byte of a PORT (but do not be within the same byte of a PORT (but do not
need to be sequential or contiguous within that need to be sequential or contiguous within that
byte) for more efficient RAM utilization. For byte) for more efficient RAM utilization. For
two concurrent chains, same principle but 16-bit two concurrent chains, same principle but 16-bit
word instead of byte. word instead of byte.
@param addrCount Number of row address lines required of matrix. @param addrCount Number of row address lines required of matrix.
Total pixel height is then 2 x 2^addrCount, e.g. Total pixel height is then 2 x 2^addrCount, e.g.
32-pixel-tall matrices have 4 row address lines. 32-pixel-tall matrices have 4 row address lines.
@param addrList A uint8_t array of pins (Arduino pin numbering), @param addrList A uint8_t array of pins (Arduino pin numbering),
one per row address line. one per row address line.
@param clockPin RGB clock pin (Arduino pin #). @param clockPin RGB clock pin (Arduino pin #).
@param latchPin RGB data latch pin (Arduino pin #). @param latchPin RGB data latch pin (Arduino pin #).
@param oePin Output enable pin (Arduino pin #), active low. @param oePin Output enable pin (Arduino pin #), active low.
@param doubleBuffer If true, two matrix buffers are allocated, @param doubleBuffer If true, two matrix buffers are allocated,
so changing display contents doesn't introduce so changing display contents doesn't introduce
artifacts mid-conversion. Requires ~2X RAM. artifacts mid-conversion. Requires ~2X RAM.
@param timer Pointer to timer peripheral or timer-related @param timer Pointer to timer peripheral or timer-related
struct (architecture-dependent), or NULL to struct (architecture-dependent), or NULL to
use a default timer ID (also arch-dependent). use a default timer ID (also arch-dependent).
*/ */
Adafruit_Protomatter(uint16_t bitWidth, uint8_t bitDepth, Adafruit_Protomatter(uint16_t bitWidth, uint8_t bitDepth, uint8_t rgbCount,
uint8_t rgbCount, uint8_t *rgbList, uint8_t *rgbList, uint8_t addrCount, uint8_t *addrList,
uint8_t addrCount, uint8_t *addrList, uint8_t clockPin, uint8_t latchPin, uint8_t oePin,
uint8_t clockPin, uint8_t latchPin, uint8_t oePin, bool doubleBuffer, void *timer = NULL);
bool doubleBuffer, void *timer=NULL); ~Adafruit_Protomatter(void);
~Adafruit_Protomatter(void);
/*! /*!
@brief Start a Protomatter matrix display running -- initialize @brief Start a Protomatter matrix display running -- initialize
pins, timer and interrupt into existence. pins, timer and interrupt into existence.
@return A ProtomatterStatus status, one of: @return A ProtomatterStatus status, one of:
PROTOMATTER_OK if everything is good. PROTOMATTER_OK if everything is good.
PROTOMATTER_ERR_PINS if data and/or clock pins are split PROTOMATTER_ERR_PINS if data and/or clock pins are split
across different PORTs. across different PORTs.
PROTOMATTER_ERR_MALLOC if insufficient RAM to allocate PROTOMATTER_ERR_MALLOC if insufficient RAM to allocate
display memory. display memory.
PROTOMATTER_ERR_ARG if a bad value was passed to the PROTOMATTER_ERR_ARG if a bad value was passed to the
constructor. constructor.
*/ */
ProtomatterStatus begin(void); ProtomatterStatus begin(void);
/*! /*!
@brief Process data from GFXcanvas16 to the matrix framebuffer's @brief Process data from GFXcanvas16 to the matrix framebuffer's
internal format for display. internal format for display.
*/ */
void show(void); void show(void);
/*! /*!
@brief Returns current value of frame counter and resets its value @brief Returns current value of frame counter and resets its value
to zero. Two calls to this, timed one second apart (or use to zero. Two calls to this, timed one second apart (or use
math with other intervals), can be used to get a rough math with other intervals), can be used to get a rough
frames-per-second value for the matrix (since this is frames-per-second value for the matrix (since this is
difficult to estimate beforehand). difficult to estimate beforehand).
@return Frame count since previous call to function, as a uint32_t. @return Frame count since previous call to function, as a uint32_t.
*/ */
uint32_t getFrameCount(void); uint32_t getFrameCount(void);
private:
Protomatter_core core; // Underlying C struct private:
void convert_byte(uint8_t *dest); // GFXcanvas16-to-matrix Protomatter_core core; // Underlying C struct
void convert_word(uint16_t *dest); // conversion functions void convert_byte(uint8_t *dest); // GFXcanvas16-to-matrix
void convert_long(uint32_t *dest); // for 8/16/32 bit bufs void convert_word(uint16_t *dest); // conversion functions
void convert_long(uint32_t *dest); // for 8/16/32 bit bufs
}; };
#endif // _ADAFRUIT_PROTOMATTER_H_ #endif // _ADAFRUIT_PROTOMATTER_H_

1833
arch.h

File diff suppressed because it is too large Load diff

932
core.c

File diff suppressed because it is too large Load diff

98
core.h
View file

@ -21,15 +21,15 @@
extern "C" { extern "C" {
#endif #endif
#include <stdint.h>
#include <stdbool.h> #include <stdbool.h>
#include <stdint.h>
/** Status type returned by some functions. */ /** Status type returned by some functions. */
typedef enum { typedef enum {
PROTOMATTER_OK, // Everything is hunky-dory! PROTOMATTER_OK, // Everything is hunky-dory!
PROTOMATTER_ERR_PINS, // Clock and/or data pins on different PORTs PROTOMATTER_ERR_PINS, // Clock and/or data pins on different PORTs
PROTOMATTER_ERR_MALLOC, // Couldn't allocate memory for display PROTOMATTER_ERR_MALLOC, // Couldn't allocate memory for display
PROTOMATTER_ERR_ARG, // Bad input to function PROTOMATTER_ERR_ARG, // Bad input to function
} ProtomatterStatus; } ProtomatterStatus;
/** Struct for matrix control lines NOT related to RGB data or clock, i.e. /** Struct for matrix control lines NOT related to RGB data or clock, i.e.
@ -39,10 +39,10 @@ typedef enum {
RGB data but do NOT need the set or clear registers, so those items are RGB data but do NOT need the set or clear registers, so those items are
also declared as separate things in the core structure that follows. */ also declared as separate things in the core structure that follows. */
typedef struct { typedef struct {
volatile void *setReg; ///< GPIO bit set register volatile void *setReg; ///< GPIO bit set register
volatile void *clearReg; ///< GPIO bit clear register volatile void *clearReg; ///< GPIO bit clear register
uint32_t bit; ///< GPIO bitmask uint32_t bit; ///< GPIO bitmask
uint8_t pin; ///< Some unique ID, e.g. Arduino pin # uint8_t pin; ///< Some unique ID, e.g. Arduino pin #
} _PM_pin; } _PM_pin;
/** Struct with info about an RGB matrix chain and lots of state and buffer /** Struct with info about an RGB matrix chain and lots of state and buffer
@ -56,38 +56,38 @@ typedef struct {
to put any toggle-specific stuff at the end of the struct with an ifdef to put any toggle-specific stuff at the end of the struct with an ifdef
check, but that's just dirty pool and asking for trouble.) */ check, but that's just dirty pool and asking for trouble.) */
typedef struct { typedef struct {
void *timer; ///< Arch-specific timer/counter info void *timer; ///< Arch-specific timer/counter info
void *setReg; ///< RGBC bit set register (cast to use) void *setReg; ///< RGBC bit set register (cast to use)
void *clearReg; ///< RGBC bit clear register " void *clearReg; ///< RGBC bit clear register "
void *toggleReg; ///< RGBC bit toggle register " void *toggleReg; ///< RGBC bit toggle register "
uint8_t *rgbPins; ///< Array of RGB data pins (mult of 6) uint8_t *rgbPins; ///< Array of RGB data pins (mult of 6)
void *rgbMask; ///< PORT bit mask for each RGB pin void *rgbMask; ///< PORT bit mask for each RGB pin
uint32_t clockMask; ///< PORT bit mask for RGB clock uint32_t clockMask; ///< PORT bit mask for RGB clock
uint32_t rgbAndClockMask; ///< PORT bit mask for RGB data + clock uint32_t rgbAndClockMask; ///< PORT bit mask for RGB data + clock
volatile void *addrPortToggle; ///< See singleAddrPort below volatile void *addrPortToggle; ///< See singleAddrPort below
void *screenData; ///< Per-bitplane RGB data for matrix void *screenData; ///< Per-bitplane RGB data for matrix
_PM_pin latch; ///< RGB data latch _PM_pin latch; ///< RGB data latch
_PM_pin oe; ///< !OE (LOW out enable) _PM_pin oe; ///< !OE (LOW out enable)
_PM_pin *addr; ///< Array of address pins _PM_pin *addr; ///< Array of address pins
uint32_t bufferSize; ///< Bytes per matrix buffer uint32_t bufferSize; ///< Bytes per matrix buffer
uint32_t bitZeroPeriod; ///< Bitplane 0 timer period uint32_t bitZeroPeriod; ///< Bitplane 0 timer period
uint32_t minPeriod; ///< Plane 0 timer period for ~250Hz uint32_t minPeriod; ///< Plane 0 timer period for ~250Hz
volatile uint32_t frameCount; ///< For estimating refresh rate volatile uint32_t frameCount; ///< For estimating refresh rate
uint16_t width; ///< Matrix chain width in bits uint16_t width; ///< Matrix chain width in bits
uint8_t bytesPerElement; ///< Using 8, 16 or 32 bits of PORT? uint8_t bytesPerElement; ///< Using 8, 16 or 32 bits of PORT?
uint8_t clockPin; ///< RGB clock pin identifier uint8_t clockPin; ///< RGB clock pin identifier
uint8_t parallel; ///< Number of concurrent matrix outs uint8_t parallel; ///< Number of concurrent matrix outs
uint8_t numAddressLines; ///< Number of address line pins uint8_t numAddressLines; ///< Number of address line pins
uint8_t portOffset; ///< Active 8- or 16-bit pos. in PORT uint8_t portOffset; ///< Active 8- or 16-bit pos. in PORT
uint8_t numPlanes; ///< Display bitplanes (1 to 6) uint8_t numPlanes; ///< Display bitplanes (1 to 6)
uint8_t numRowPairs; ///< Addressable row pairs uint8_t numRowPairs; ///< Addressable row pairs
bool doubleBuffer; ///< 2X buffers for clean switchover bool doubleBuffer; ///< 2X buffers for clean switchover
bool singleAddrPort; ///< If 1, all addr lines on same PORT bool singleAddrPort; ///< If 1, all addr lines on same PORT
volatile uint8_t activeBuffer; ///< Index of currently-displayed buf volatile uint8_t activeBuffer; ///< Index of currently-displayed buf
volatile uint8_t plane; ///< Current bitplane (changes in ISR) volatile uint8_t plane; ///< Current bitplane (changes in ISR)
volatile uint8_t row; ///< Current scanline (changes in ISR) volatile uint8_t row; ///< Current scanline (changes in ISR)
volatile uint8_t prevRow; ///< Scanline from prior ISR volatile uint8_t prevRow; ///< Scanline from prior ISR
volatile bool swapBuffers; ///< If 1, awaiting double-buf switch volatile bool swapBuffers; ///< If 1, awaiting double-buf switch
} Protomatter_core; } Protomatter_core;
// Protomatter core function prototypes. Environment-specific code (like the // Protomatter core function prototypes. Environment-specific code (like the
@ -148,12 +148,12 @@ typedef struct {
PROTOMATTER_ERR_ARG if a bad value (core or timer pointer) was PROTOMATTER_ERR_ARG if a bad value (core or timer pointer) was
passed in. passed in.
*/ */
extern ProtomatterStatus _PM_init(Protomatter_core *core, extern ProtomatterStatus _PM_init(Protomatter_core *core, uint16_t bitWidth,
uint16_t bitWidth, uint8_t bitDepth, uint8_t bitDepth, uint8_t rgbCount,
uint8_t rgbCount, uint8_t *rgbList, uint8_t *rgbList, uint8_t addrCount,
uint8_t addrCount, uint8_t *addrList, uint8_t *addrList, uint8_t clockPin,
uint8_t clockPin, uint8_t latchPin, uint8_t oePin, uint8_t latchPin, uint8_t oePin,
bool doubleBuffer, void *timer); bool doubleBuffer, void *timer);
/*! /*!
@brief Allocate display buffers and populate additional elements of a @brief Allocate display buffers and populate additional elements of a
@ -246,8 +246,8 @@ extern uint32_t _PM_timerGetCount(void *tptr);
@param width Width of canvas in pixels, as this may be different than @param width Width of canvas in pixels, as this may be different than
the matrix pixel width due to row padding. the matrix pixel width due to row padding.
*/ */
extern void _PM_convert_565(Protomatter_core *core, extern void _PM_convert_565(Protomatter_core *core, uint16_t *source,
uint16_t *source, uint16_t width); uint16_t width);
/*! /*!
@brief Pauses until the next vertical blank to avoid 'tearing' animation @brief Pauses until the next vertical blank to avoid 'tearing' animation