Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
SN74HC595< N > Class Template Reference

Driver for the 74HC595 shift register. More...

#include <SN74HC595GPO.hxx>

Inheritance diagram for SN74HC595< N >:
OSThread

Public Member Functions

 SN74HC595 (void(*request_refresh_operation)(void))
 Constructor.
 
void init (const char *spi_name, int priority=get_priority_max())
 Initialize the SN74HC595 settings.
 
void refresh (bool from_isr=false)
 Triggers the helper thread to wakeup and refresh the outputs.
 
- Public Member Functions inherited from OSThread
 OSThread (const char *name, int priority, size_t stack_size, void *(*start_routine)(void *), void *arg)
 Create a thread.
 
 OSThread ()
 Creates a thread via inheritance.
 
void start (const char *name, int priority, size_t stack_size)
 Starts the thread.
 
virtual ~OSThread ()
 Default destructor.
 
bool is_created ()
 
void inherit ()
 Inherits the current thread.
 
os_thread_t get_handle ()
 
void lock_to_thread ()
 Sets the thread handle to the current calling thread's.
 
void unlock_from_thread ()
 Resets the thread handle to none.
 

Private Member Functions

void * entry () override
 User entry point for the created thread.
 
 DISALLOW_COPY_AND_ASSIGN (SN74HC595)
 

Private Attributes

void(* requestRefreshOperation_ )(void)
 Request that the GPIO cache be refreshed.
 
int spiFd_
 SPI bus that accesses the SN74HC595.
 
OSSem sem_
 semaphore for posting events
 
uint8_t ioPending_: 1
 true if an update is pending
 
std::atomic< uint8_t > gpoData_ [N]
 local copy of the expansion output data
 

Static Private Attributes

static constexpr uint32_t SPI_MAX_SPEED_HZ = 4000000
 maximum SPI clock speed in Hz
 

Friends

class SN74HC595GPO< N >
 Allow access to SN74HC595 from SN74HC595GPO.
 

Additional Inherited Members

- Static Public Member Functions inherited from OSThread
static int getpriority (OSThread *thread)
 Return the current thread priority.
 
static int get_priority (OSThread *thread)
 Return the current thread priority.
 
static int get_priority_min ()
 Get the minimum thread priority.
 
static int get_priority_max ()
 Get the maximum thread priority.
 

Detailed Description

template<uint8_t N = 1>
class SN74HC595< N >

Driver for the 74HC595 shift register.

Note: This driver makes use of std::atomic and requires an implementation of std::atomic on any platform that makes use of it. For example, at the time of creating this device driver, ARMv7-M (Cortex-M3/M4/M4F) does have support for std::atomic, while ARMv6-M (Cortex-M0) does not.

Template Parameters
Nnumber of chips on the bus, starting at 1

Definition at line 58 of file SN74HC595GPO.hxx.

Constructor & Destructor Documentation

◆ SN74HC595()

template<uint8_t N = 1>
SN74HC595< N >::SN74HC595 ( void(*)(void)  request_refresh_operation)
inline

Constructor.

Parameters
request_refresh_operationThis is an application specific callback for triggering a sequence of events that will result in refresh() being called. The exact implementation is application specific, and mostly is determined by whether or not these outputs must be toggled from an interrupt.

Definition at line 67 of file SN74HC595GPO.hxx.

Member Function Documentation

◆ entry()

template<uint8_t N = 1>
void * SN74HC595< N >::entry ( )
inlineoverrideprivatevirtual

User entry point for the created thread.

Returns
exit status

Reimplemented from OSThread.

Definition at line 128 of file SN74HC595GPO.hxx.

◆ init()

template<uint8_t N = 1>
void SN74HC595< N >::init ( const char *  spi_name,
int  priority = get_priority_max() 
)
inline

Initialize the SN74HC595 settings.

Typically called in hw_postinit(), not hw_preinit() or hw_init().

Parameters
spi_namespi interface that the SN74HC595 is on
priorityhelper thread priority

Definition at line 84 of file SN74HC595GPO.hxx.

◆ refresh()

template<uint8_t N = 1>
void SN74HC595< N >::refresh ( bool  from_isr = false)
inline

Triggers the helper thread to wakeup and refresh the outputs.

Parameters
from_isrtrue if called from an ISR.

Definition at line 105 of file SN74HC595GPO.hxx.

Friends And Related Symbol Documentation

◆ SN74HC595GPO< N >

template<uint8_t N = 1>
friend class SN74HC595GPO< N >
friend

Allow access to SN74HC595 from SN74HC595GPO.

Definition at line 154 of file SN74HC595GPO.hxx.

Member Data Documentation

◆ gpoData_

template<uint8_t N = 1>
std::atomic<uint8_t> SN74HC595< N >::gpoData_[N]
private

local copy of the expansion output data

Definition at line 154 of file SN74HC595GPO.hxx.

◆ ioPending_

template<uint8_t N = 1>
uint8_t SN74HC595< N >::ioPending_
private

true if an update is pending

Definition at line 151 of file SN74HC595GPO.hxx.

◆ requestRefreshOperation_

template<uint8_t N = 1>
void(* SN74HC595< N >::requestRefreshOperation_) (void)
private

Request that the GPIO cache be refreshed.

Definition at line 147 of file SN74HC595GPO.hxx.

◆ sem_

template<uint8_t N = 1>
OSSem SN74HC595< N >::sem_
private

semaphore for posting events

Definition at line 150 of file SN74HC595GPO.hxx.

◆ SPI_MAX_SPEED_HZ

template<uint8_t N = 1>
constexpr uint32_t SN74HC595< N >::SPI_MAX_SPEED_HZ = 4000000
staticconstexprprivate

maximum SPI clock speed in Hz

Definition at line 124 of file SN74HC595GPO.hxx.

◆ spiFd_

template<uint8_t N = 1>
int SN74HC595< N >::spiFd_
private

SPI bus that accesses the SN74HC595.

Definition at line 149 of file SN74HC595GPO.hxx.


The documentation for this class was generated from the following file: