Bluenet  5.7.0
Bluenet, firmware for nRF52 smart home devices
Loading...
Searching...
No Matches
cs_Gpio.h
Go to the documentation of this file.
1/*
2 * Author: Crownstone Team
3 * Copyright: Crownstone (https://crownstone.rocks)
4 * Date: 18 Feb., 2021
5 * Triple-license: LGPLv3+, Apache License, and/or MIT
6 */
7#pragma once
8
9#include <ble/cs_Nordic.h>
10#include <cfg/cs_Boards.h>
11#include <cfg/cs_Config.h>
13
14#include <vector>
15
16#define TOTAL_PIN_COUNT GPIO_INDEX_COUNT + BUTTON_COUNT + LED_COUNT
17
18typedef uint8_t pin_t;
19
20enum GpioDirection { INPUT = 1, OUTPUT = 2, SENSE = 3 };
21
22enum GpioPullResistor { NONE = 0, UP = 1, DOWN = 2 };
23
24enum GpioPolarity { HITOLO = 1, LOTOHI = 2, TOGGLE = 3 };
25
26typedef struct pin_info_t {
27 bool event;
28 uint8_t direction;
30
31class Gpio : public EventListener {
32
33public:
35 static Gpio& getInstance();
36
38 void init(const boards_config_t& board);
39
41 void handleEvent(event_t& event);
42
45
46private:
49
51 Gpio(Gpio const&);
52
54 void operator=(Gpio const&);
55
57 void tick();
58
61
63 bool pinExists(uint8_t pin_index);
64
69 pin_t getPin(uint8_t pin_index);
70
72 bool isLedPin(uint8_t pin_index);
73
75 cs_ret_code_t configure(uint8_t pin_index, GpioDirection direction, GpioPullResistor pull, GpioPolarity polarity);
76
78
82 cs_ret_code_t write(uint8_t pin_index, uint8_t* buf, uint8_t& length);
83
85 cs_ret_code_t read(uint8_t pin_index, uint8_t* buf, uint8_t& length);
86
89
92};
Event listener.
Definition: cs_EventListener.h:17
Definition: cs_Gpio.h:31
static Gpio & getInstance()
Get singleton instance.
void tick()
Get regular ticks to send events.
const boards_config_t * _boardConfig
Board configuration.
Definition: cs_Gpio.h:91
cs_ret_code_t read(uint8_t pin_index, uint8_t *buf, uint8_t &length)
Read from pin.
pin_t getPin(uint8_t pin_index)
Return physical pin from virtual pin index.
Gpio()
Constructor.
cs_ret_code_t configure(uint8_t pin_index, GpioDirection direction, GpioPullResistor pull, GpioPolarity polarity)
Configure pin.
cs_ret_code_t write(uint8_t pin_index, uint8_t *buf, uint8_t &length)
Write to pin.
void registerEvent(pin_t pin)
Register event (from event handler)
bool pinExists(uint8_t pin_index)
Return whether pin exists on board.
Gpio(Gpio const &)
This class is a singleton, deny implementation.
bool isLedPin(uint8_t pin_index)
Return whether pin is a LED.
void operator=(Gpio const &)
This class is a singleton, deny implementation.
pin_info_t _pins[TOTAL_PIN_COUNT]
Array of virtual pin info.
Definition: cs_Gpio.h:60
bool _initialized
Initialized flag.
Definition: cs_Gpio.h:88
void handleEvent(event_t &event)
Handle incoming events.
void init(const boards_config_t &board)
Initialize (from cs_Crownstone as driver)
Author: Crownstone Team Copyright: Crownstone (https://crownstone.rocks) Date: Oct 9,...
Definition: cs_Event.h:26
#define TOTAL_PIN_COUNT
Definition: cs_Gpio.h:16
GpioDirection
Definition: cs_Gpio.h:20
@ OUTPUT
Definition: cs_Gpio.h:20
@ SENSE
Definition: cs_Gpio.h:20
@ INPUT
Definition: cs_Gpio.h:20
GpioPolarity
Definition: cs_Gpio.h:24
@ TOGGLE
Definition: cs_Gpio.h:24
@ LOTOHI
Definition: cs_Gpio.h:24
@ HITOLO
Definition: cs_Gpio.h:24
GpioPullResistor
Definition: cs_Gpio.h:22
@ DOWN
Definition: cs_Gpio.h:22
@ UP
Definition: cs_Gpio.h:22
@ NONE
Definition: cs_Gpio.h:22
uint8_t pin_t
Definition: cs_Gpio.h:18
uint16_t cs_ret_code_t
Definition: cs_Typedefs.h:21
Board configuration.
Definition: cs_Boards.h:169
Definition: cs_Gpio.h:26
uint8_t direction
Definition: cs_Gpio.h:28
bool event
Definition: cs_Gpio.h:27