Multiple button groups piping to HID

This commit is contained in:
Justin C. Miller
2025-02-23 17:21:09 -08:00
parent 3a8fa7d08f
commit eac47947cd
10 changed files with 364 additions and 149 deletions

View File

@@ -16,16 +16,38 @@ enum class reg : uint8_t {
olata, olatb,
};
class gpios
enum class direction { out, in };
class extender
{
public:
gpios(uint8_t addr);
extender(uint8_t addr);
int read(reg r, uint8_t *value);
int write(reg r, uint8_t value);
bool init();
void set_direction(unsigned bank, unsigned pin, direction dir);
void set_polarity(unsigned bank, unsigned pin, bool reversed);
void set_pullup(unsigned bank, unsigned pin, bool enabled);
void set_irq(unsigned bank, unsigned pin, bool enabled);
void set_gpio(unsigned bank, unsigned pin, bool on);
void set_gpios(unsigned bank, uint8_t values);
bool get_gpio(unsigned bank, unsigned pin);
uint8_t get_gpios(unsigned bank);
private:
template<reg base_reg, typename Value>
void set_field(unsigned bank, unsigned pin, Value value, uint8_t (&current)[2]);
int write(reg r, uint8_t value);
int read(reg r, uint8_t *value, unsigned count);
uint8_t m_addr;
uint8_t m_direction[2];
uint8_t m_polarity[2];
uint8_t m_pullup[2];
uint8_t m_irq[2];
};
} // namespace mcp23017