b15f/firmware/mcp23s17.h

73 lines
1.9 KiB
C
Raw Normal View History

2019-03-25 12:00:22 +00:00
#ifndef MCP23S17_H
#define MCP23S17_H
#include "spi.h"
class MCP23S17
{
public:
2019-04-03 11:49:32 +00:00
/**
* Erzeugt ein neues Expander Objekt mit fester Referenz
* zur SPI Verbindung und fester SPI-'Adresse'
*/
2019-04-03 11:30:57 +00:00
MCP23S17(volatile SPI&, SPIADR adr);
2019-04-03 11:49:32 +00:00
/**
* Setzt die Richtung (In/Out) aller Pins von Port A
* Bit gesetzt: Pin ist Eingang, sonst Ausgang
* \param dir Richtungen für gesamten Port A
*/
2019-04-03 06:40:14 +00:00
void setDirA(uint8_t dir) const volatile;
2019-04-03 11:49:32 +00:00
/**
* Setzt die Richtung (In/Out) aller Pins von Port B
* Bit gesetzt: Pin ist Eingang, sonst Ausgang
* \param dir Richtungen für gesamten Port B
*/
2019-04-03 06:40:14 +00:00
void setDirB(uint8_t dir) const volatile;
2019-04-03 11:49:32 +00:00
/**
* Setzt den Zustand (High/Low) aller Pins von Port A
* Bit gesetzt: Pin ist High, sonst Low
* \param port Zustände für gesamten Port A
*/
void writePortA(uint8_t port) const volatile;
/**
* Setzt den Zustand (High/Low) aller Pins von Port B
* Bit gesetzt: Pin ist High, sonst Low
* \param port Zustände für gesamten Port B
*/
void writePortB(uint8_t port) const volatile;
/**
* Liest den Zustand (High/Low) aller Pins von Port A
* \return Zustände für gesamten Port A
*/
2019-04-03 06:40:14 +00:00
uint8_t readPortA(void) const volatile;
2019-04-03 11:49:32 +00:00
/**
* Liest den Zustand (High/Low) aller Pins von Port B
* \return Zustände für gesamten Port B
*/
2019-04-03 06:40:14 +00:00
uint8_t readPortB(void) const volatile;
2019-03-25 12:00:22 +00:00
private:
2019-04-03 11:49:32 +00:00
// Referenz zur SPI Verbindung
volatile SPI& spi;
// SPI-'Adresse' dieses Expanders
2019-04-03 11:30:57 +00:00
const SPIADR adr;
2019-04-03 06:40:14 +00:00
// constants
2019-04-03 11:49:32 +00:00
constexpr static uint8_t MCP23S17_DIRA = 0x00;
constexpr static uint8_t MCP23S17_DIRB = 0x01;
constexpr static uint8_t MCP23S17_PORTA = 0x12;
constexpr static uint8_t MCP23S17_PORTB = 0x13;
constexpr static uint8_t MCP23S17_READ = 0x01;
constexpr static uint8_t MCP23S17_WRITE = 0x00;
2019-04-03 06:40:14 +00:00
constexpr static uint8_t MCP23S17_OPCODE = 0x40;
2019-03-25 12:00:22 +00:00
};
#endif // MCP23S17_H