Bluenet  5.7.0
Bluenet, firmware for nRF52 smart home devices
Loading...
Searching...
No Matches
cs_Twi.h
Go to the documentation of this file.
1/*
2 * Author: Crownstone Team
3 * Copyright: Crownstone (https://crownstone.rocks)
4 * Date: Dec 9, 2020
5 * License: LGPLv3+, Apache License 2.0, and/or MIT (triple-licensed)
6 */
7
8#pragma once
9
10#include <ble/cs_Nordic.h>
11#include <cfg/cs_Boards.h>
13
14enum class TwiIsrEvent { Read, Write, Error };
18class Twi : public EventListener {
19public:
23 static Twi& getInstance();
24
30 void init(const boards_config_t& board);
31
38
47 void write(uint8_t address, uint8_t* data, size_t length, bool stop);
48
56 void read(uint8_t address, uint8_t* data, size_t& length);
57
63 void handleEvent(event_t& event);
64
68 void isrEvent(TwiIsrEvent event);
69
70protected:
71 // Local struct to store configuration.
72 static const nrfx_twi_t _twi;
73
74private:
75 Twi();
76 Twi(Twi const&);
77 void operator=(Twi const&);
78
79 // Local config for driver
80 nrfx_twi_config_t _config;
81
82 // Initialized flag
84
85 // Initialized flag
87
88 // Event is read
90
91 // Error event
93};
Event listener.
Definition: cs_EventListener.h:17
Class that implements twi/i2c.
Definition: cs_Twi.h:18
void handleEvent(event_t &event)
Incoming events.
static Twi & getInstance()
Construct twi/i2c instance.
bool _eventRead
Definition: cs_Twi.h:89
void init(const boards_config_t &board)
Init twi with board configuration (nothing is happening to the pins yet).
bool _eventError
Definition: cs_Twi.h:92
void isrEvent(TwiIsrEvent event)
Events from the hardware.
Twi(Twi const &)
bool _initialized
Definition: cs_Twi.h:83
void read(uint8_t address, uint8_t *data, size_t &length)
Read data from given address.
void write(uint8_t address, uint8_t *data, size_t length, bool stop)
Write data to given address.
void initBus(cs_twi_init_t &twi)
Init twi as master on the i2c bus.
bool _initializedBus
Definition: cs_Twi.h:86
void operator=(Twi const &)
nrfx_twi_config_t _config
Definition: cs_Twi.h:80
static const nrfx_twi_t _twi
Definition: cs_Twi.h:72
Author: Crownstone Team Copyright: Crownstone (https://crownstone.rocks) Date: Oct 9,...
Definition: cs_Event.h:26
TwiIsrEvent
Definition: cs_Twi.h:14
Board configuration.
Definition: cs_Boards.h:169
Definition: cs_PacketsInternal.h:394