NEORV32 - Software Framework Documentation
Loading...
Searching...
No Matches
neorv32_twi.h
Go to the documentation of this file.
1// #################################################################################################
2// # << NEORV32: neorv32_twi.h - Two-Wire Interface Controller (TWI) HW Driver >> #
3// # ********************************************************************************************* #
4// # BSD 3-Clause License #
5// # #
6// # The NEORV32 RISC-V Processor, https://github.com/stnolting/neorv32 #
7// # Copyright (c) 2024, Stephan Nolting. All rights reserved. #
8// # #
9// # Redistribution and use in source and binary forms, with or without modification, are #
10// # permitted provided that the following conditions are met: #
11// # #
12// # 1. Redistributions of source code must retain the above copyright notice, this list of #
13// # conditions and the following disclaimer. #
14// # #
15// # 2. Redistributions in binary form must reproduce the above copyright notice, this list of #
16// # conditions and the following disclaimer in the documentation and/or other materials #
17// # provided with the distribution. #
18// # #
19// # 3. Neither the name of the copyright holder nor the names of its contributors may be used to #
20// # endorse or promote products derived from this software without specific prior written #
21// # permission. #
22// # #
23// # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS #
24// # OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF #
25// # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE #
26// # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, #
27// # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE #
28// # GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED #
29// # AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING #
30// # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED #
31// # OF THE POSSIBILITY OF SUCH DAMAGE. #
32// #################################################################################################
33
34
35/**********************************************************************/
42#ifndef neorv32_twi_h
43#define neorv32_twi_h
44
45/**********************************************************************/
50typedef volatile struct __attribute__((packed,aligned(4))) {
51 uint32_t CTRL;
52 uint32_t DCMD;
54
56#define NEORV32_TWI ((neorv32_twi_t*) (NEORV32_TWI_BASE))
57
77
88/**********************************************************************/
92#define TWI_CMD_NOP (0b00) // no operation
93#define TWI_CMD_START (0b01) // generate start condition
94#define TWI_CMD_STOP (0b10) // generate stop condition
95#define TWI_CMD_RTX (0b11) // transmit+receive data byte
99/**********************************************************************/
103int neorv32_twi_available(void);
104void neorv32_twi_setup(int prsc, int cdiv, int clkstr);
106void neorv32_twi_disable(void);
107void neorv32_twi_enable(void);
108
109int neorv32_twi_busy(void);
110int neorv32_twi_get(uint8_t *data);
111
112int neorv32_twi_trans(uint8_t *data, int mack);
115
116void neorv32_twi_send_nonblocking(uint8_t data, int mack);
122#endif // neorv32_twi_h
void neorv32_twi_enable(void)
Definition neorv32_twi.c:106
void neorv32_twi_send_nonblocking(uint8_t data, int mack)
Definition neorv32_twi.c:207
int neorv32_twi_get_fifo_depth(void)
Definition neorv32_twi.c:87
NEORV32_TWI_DCMD_enum
Definition neorv32_twi.h:79
@ TWI_DCMD_CMD_LO
Definition neorv32_twi.h:83
@ TWI_DCMD_MSB
Definition neorv32_twi.h:81
@ TWI_DCMD_CMD_HI
Definition neorv32_twi.h:84
@ TWI_DCMD_LSB
Definition neorv32_twi.h:80
@ TWI_DCMD_ACK
Definition neorv32_twi.h:82
int neorv32_twi_busy(void)
Definition neorv32_twi.c:117
void neorv32_twi_generate_start(void)
Definition neorv32_twi.c:191
NEORV32_TWI_CTRL_enum
Definition neorv32_twi.h:59
@ TWI_CTRL_FIFO_MSB
Definition neorv32_twi.h:71
@ TWI_CTRL_EN
Definition neorv32_twi.h:60
@ TWI_CTRL_BUSY
Definition neorv32_twi.h:75
@ TWI_CTRL_CDIV1
Definition neorv32_twi.h:65
@ TWI_CTRL_PRSC2
Definition neorv32_twi.h:63
@ TWI_CTRL_FIFO_LSB
Definition neorv32_twi.h:70
@ TWI_CTRL_CDIV0
Definition neorv32_twi.h:64
@ TWI_CTRL_PRSC1
Definition neorv32_twi.h:62
@ TWI_CTRL_PRSC0
Definition neorv32_twi.h:61
@ TWI_CTRL_CDIV3
Definition neorv32_twi.h:67
@ TWI_CTRL_TX_FULL
Definition neorv32_twi.h:73
@ TWI_CTRL_CDIV2
Definition neorv32_twi.h:66
@ TWI_CTRL_CLKSTR
Definition neorv32_twi.h:68
@ TWI_CTRL_RX_AVAIL
Definition neorv32_twi.h:74
int neorv32_twi_get(uint8_t *data)
Definition neorv32_twi.c:134
void neorv32_twi_setup(int prsc, int cdiv, int clkstr)
Definition neorv32_twi.c:69
void neorv32_twi_generate_stop_nonblocking(void)
Definition neorv32_twi.c:221
int neorv32_twi_available(void)
Definition neorv32_twi.c:51
int neorv32_twi_trans(uint8_t *data, int mack)
Definition neorv32_twi.c:155
void neorv32_twi_generate_stop(void)
Definition neorv32_twi.c:178
void neorv32_twi_generate_start_nonblocking(void)
Definition neorv32_twi.c:232
void neorv32_twi_disable(void)
Definition neorv32_twi.c:97
Definition neorv32_twi.h:50
uint32_t CTRL
Definition neorv32_twi.h:51
uint32_t DCMD
Definition neorv32_twi.h:52