|
PropWare
3.0.0.229
C++ objects and CMake build system for Parallax Propeller
|
Go to the documentation of this file.
66 static const Pin::Mask DEFAULT_SCL_MASK = Pin::Mask::P28;
67 static const Pin::Mask DEFAULT_SDA_MASK = Pin::Mask::P29;
68 static const unsigned int DEFAULT_FREQUENCY = 400000;
79 const unsigned int frequency = DEFAULT_FREQUENCY)
80 : m_scl(sclMask,
Pin::Dir::IN),
81 m_sda(sdaMask,
Pin::Dir::IN) {
95 this->m_clockDelay =
CLKFREQ / (frequency << 1);
141 FC_START(
"PutByteStart",
"PutByteEnd")
143 " mov %[_dataMask], #256 \n\t"
144 " mov %[_result], #0 \n\t"
145 " mov %[_nextCnt], cnt \n\t"
146 " add %[_nextCnt], %[_clockDelay] \n\t"
151 " shr %[_dataMask], #1 \n\t"
152 " and %[_dataMask], %[_dataByte] wz,nr \n\t"
153 " muxz dira, %[_SDAMask] \n\t"
156 " waitcnt %[_nextCnt], %[_clockDelay] \n\t"
157 " andn dira, %[_SCLMask] \n\t"
158 " waitcnt %[_nextCnt], %[_clockDelay] \n\t"
159 " or dira, %[_SCLMask] \n\t"
162 " djnz %[_dataMask], #" FC_ADDR(
"PutByteLoop%=",
"PutByteStart")
" nr \n\t"
165 " andn dira, %[_SDAMask] \n\t"
166 " waitcnt %[_nextCnt], %[_clockDelay] \n\t"
167 " andn dira, %[_SCLMask] \n\t"
168 " waitcnt %[_nextCnt], %[_clockDelay] \n\t"
169 " mov %[_temp], ina \n\t"
170 " and %[_SDAMask], %[_temp] wz,nr \n\t"
171 " muxz %[_result], #1 \n\t"
172 " or dira, %[_SCLMask] \n\t"
173 " or dira, %[_SDAMask] \n\t"
177 [_dataMask]
"=&r"(dataMask),
178 [_result]
"=&r"(result),
179 [_nextCnt]
"=&r"(nextCnt),
182 [_SDAMask]
"r"(this->m_sda.get_mask()),
183 [_SCLMask]
"r"(this->m_scl.get_mask()),
184 [_dataByte]
"r"(
byte),
185 [_clockDelay]
"r"(m_clockDelay));
187 return (
bool) result;
204 FC_START(
"GetByteStart",
"GetByteEnd")
206 " andn dira, %[_SDAMask] \n\t"
207 " mov %[_dataMask], #256 \n\t"
208 " mov %[_result], #0 \n\t"
209 " mov %[_nextCnt], cnt \n\t"
210 " add %[_nextCnt], %[_clockDelay] \n\t"
216 " waitcnt %[_nextCnt], %[_clockDelay] \n\t"
217 " shr %[_dataMask], #1 \n\t"
220 " andn dira, %[_SCLMask] \n\t"
221 " waitcnt %[_nextCnt], %[_clockDelay] \n\t"
222 " mov %[_temp], ina \n\t"
223 " and %[_temp], %[_SDAMask] nr,wz \n\t"
224 " muxnz %[_result], %[_dataMask] \n\t"
225 " or dira, %[_SCLMask] \n\t"
228 " djnz %[_dataMask], #" FC_ADDR(
"GetByteLoop%=",
"GetByteStart")
" nr \n\t"
232 " and %[_acknowledge], #1 nr,wz \n\t"
234 " muxnz dira, %[_SDAMask] \n\t"
235 " waitcnt %[_nextCnt], %[_clockDelay] \n\t"
236 " andn dira, %[_SCLMask] \n\t"
237 " waitcnt %[_nextCnt], %[_clockDelay] \n\t"
239 " or dira, %[_SCLMask] \n\t"
240 " or dira, %[_SDAMask] \n\t"
243 [_dataMask]
"=&r"(dataMask),
244 [_result]
"=&r"(result),
246 [_nextCnt]
"=&r"(nextCnt)
249 [_SDAMask]
"r"(this->m_sda.get_mask()),
250 [_SCLMask]
"r"(this->m_scl.get_mask()),
251 [_acknowledge]
"r"(acknowledge),
252 [_clockDelay]
"r"(m_clockDelay));
254 return (uint8_t) result;
272 bool ping (
const uint8_t device)
const {
296 bool put (
const uint8_t device,
const T address,
const uint8_t
byte)
const {
302 result = this->send_address(address);
327 uint8_t
get (
const uint8_t device,
const T address)
const {
329 uint8_t dataByte =
static_cast<uint8_t
>(-1);
334 result &= this->send_address(address);
337 result &= this->
send_byte((uint8_t) (device | BIT_0));
367 bool put (
const uint8_t device,
const T address,
const uint8_t bytes[],
const size_t size)
const {
372 result = this->send_address(address);
374 for (
unsigned int i = 0; i < size; ++i) {
408 bool get (
const uint8_t device,
const T address, uint8_t bytes[],
const size_t size)
const {
413 result = this->send_address(address);
416 result = this->
send_byte((uint8_t) (device | 0x01));
420 for (; i < size - 1; ++i)
450 bool put (
const uint8_t device,
const uint8_t
byte)
const {
483 bool get (
const uint8_t device, uint8_t bytes[],
const size_t size)
const {
485 bool result = this->
send_byte((uint8_t) (device | 0x01));
488 for (i = 0; i < size - 1; ++i)
500 bool send_address (
const uint8_t address)
const {
507 bool send_address (
const uint16_t address)
const {
508 bool result = this->
send_byte((
const uint8_t) (address >> 8));
509 return result && this->
send_byte((
const uint8_t) address);
519 void half_clock ()
const {
520 #ifdef __PROPELLER_CMM__
521 if (500 > m_clockDelay)
522 __asm__
volatile (
"nop;");
533 unsigned int m_clockDelay;
void set_dir_out() const
Set the port for output.
void set_frequency(const unsigned int frequency)
Set the bus frequency.
void stop() const
Output a stop condition on the I2C bus.
bool put(const uint8_t device, const T address, const uint8_t byte) const
Put a single byte with the following format:
PropWare::I2CMaster pwI2c
Global I2C instance for easy and shared use by Propeller applications (not thread safe!...
bool send_byte(const uint8_t byte) const
Output a byte on the I2C bus.
void set_dir_in() const
Set the port for input.
Utility class to handle general purpose I/O pins.
uint8_t read_byte(const bool acknowledge) const
Get a byte from the bus.
bool get(const uint8_t device, uint8_t bytes[], const size_t size) const
Get multiple bytes, no register address.
void start() const
Output a start condition on the I2C bus.
#define CLKFREQ
Returns the current clock frequency.
I2CMaster(const Pin::Mask sclMask=DEFAULT_SCL_MASK, const Pin::Mask sdaMask=DEFAULT_SDA_MASK, const unsigned int frequency=DEFAULT_FREQUENCY)
Create a basic I2C instance.
void set() const
Set selected output port high (set all pins to 1)
bool put(const uint8_t device, const uint8_t byte) const
Put a single byte, no register address, on the bus.
bool put(const uint8_t device, const T address, const uint8_t bytes[], const size_t size) const
Put multiple bytes with the following format:
#define waitcnt(a)
Wait until system counter reaches a value.
uint8_t get(const uint8_t device, const T address) const
Get a single byte with the following format:
#define CNT
The system clock count.
bool ping(const uint8_t device) const
Test for the Acknowledge of a device by sending start and the slave address.
Generic definitions and functions for the Parallax Propeller.
void clear() const
Clear selected output port (set it to 0)
bool get(const uint8_t device, const T address, uint8_t bytes[], const size_t size) const
Read multiple bytes.