sim_spi.h Source File

yasimavr: sim_spi.h Source File
yasimavr
Loading...
Searching...
No Matches
sim_spi.h
Go to the documentation of this file.
1/*
2 * sim_spi.h
3 *
4 * Copyright 2021-2026 Clement Savergne <csavergne@yahoo.com>
5
6 This file is part of yasim-avr.
7
8 yasim-avr is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
12
13 yasim-avr is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with yasim-avr. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22//=======================================================================================
23
24#ifndef __YASIMAVR_SPI_H__
25#define __YASIMAVR_SPI_H__
26
27#include "../core/sim_types.h"
28
30
31
32//=======================================================================================
51#define AVR_CTLREQ_SPI_TRANSFER (AVR_CTLREQ_BASE + 1)
52
55
56
57//=======================================================================================
58
67namespace SPI {
68
78
86
96
105
106public:
107
108 EndPoint();
109 virtual ~EndPoint() = default;
110
111 void set_serial_mode(SerialMode mode);
112 SerialMode serial_mode() const;
113
114 void set_bit_order(BitOrder order);
115 BitOrder bit_order() const;
116
117 void set_shift_data(uint8_t frame);
118 uint8_t shift_data() const;
119
120 bool complete_frame() const;
121
122protected:
123
124 void set_active(bool active);
125 bool active() const;
126
127 virtual void frame_completed();
128
133 virtual void write_data_output(bool level) = 0;
134
139 virtual bool read_data_input() = 0;
140
141 void set_shift_clock(bool state);
142 bool shift_clock() const;
143
144private:
145
146 SerialMode m_serial_mode;
147 BitOrder m_bit_order;
148 int m_step;
149 bool m_active;
150 uint8_t m_shifter;
151 bool m_sampler;
152 bool m_shift_clock;
153
154 void update_sdo();
155 void shift_and_sample();
156
157};
158
160{
161 return m_serial_mode;
162}
163
165{
166 return m_bit_order;
167}
168
173inline uint8_t EndPoint::shift_data() const
174{
175 return m_shifter;
176}
177
178inline bool EndPoint::active() const
179{
180 return m_active;
181}
182
183inline bool EndPoint::shift_clock() const
184{
185 return m_shift_clock;
186}
187
189inline bool EndPoint::complete_frame() const
190{
191 return !m_step;
192}
193
194
195}; //namespace SPI
196
197
199
200#endif //__YASIMAVR_SPI_H__
An endpoint connected to a SPI bus. Represents a device connected to a SPI bus model and acting as a ...
Definition sim_spi.h:104
bool shift_clock() const
Definition sim_spi.h:183
SerialMode serial_mode() const
Definition sim_spi.h:159
virtual bool read_data_input()=0
uint8_t shift_data() const
Definition sim_spi.h:173
bool active() const
Definition sim_spi.h:178
bool complete_frame() const
Returns true when a complete byte has been transferred/received.
Definition sim_spi.h:189
BitOrder bit_order() const
Definition sim_spi.h:164
virtual void write_data_output(bool level)=0
virtual ~EndPoint()=default
Generic Serial Peripheral Interface definitions.
Definition sim_spi.h:67
BitOrder
Definition sim_spi.h:82
@ LSBFirst
Definition sim_spi.h:84
@ MSBFirst
Definition sim_spi.h:83
SerialMode
Definition sim_spi.h:72
@ Mode3
Definition sim_spi.h:76
@ Mode0
Definition sim_spi.h:73
@ Mode1
Definition sim_spi.h:74
@ Mode2
Definition sim_spi.h:75
Line
Definition sim_spi.h:90
@ MISO
Definition sim_spi.h:92
@ MOSI
Definition sim_spi.h:93
@ Clock
Definition sim_spi.h:91
@ Select
Definition sim_spi.h:94
#define YASIMAVR_BEGIN_NAMESPACE
Definition sim_globals.h:58
#define AVR_CORE_PUBLIC_API
Definition sim_globals.h:46
#define YASIMAVR_END_NAMESPACE
Definition sim_globals.h:59