46 static const unsigned int DEFAULT_FREQUENCY = 400000;
57 const unsigned int frequency = DEFAULT_FREQUENCY) {
78 this->m_clockDelay = CLKFREQ / (frequency << 1);
91 #ifndef __PROPELLER_CMM_ 92 __asm__
volatile(
"nop");
121 FC_START(
"PutByteStart",
"PutByteEnd")
123 " mov %[datamask], #256 \n\t" 124 " mov %[result], #0 \n\t" 125 " mov %[nextCNT], cnt \n\t" 126 " add %[nextCNT], %[clockDelay] \n\t" 131 " shr %[datamask], #1 \n\t" 132 " and %[datamask], %[databyte] wz,nr \n\t" 133 " muxz dira, %[SDAMask] \n\t" 136 " waitcnt %[nextCNT], %[clockDelay] \n\t" 137 " andn dira, %[SCLMask] \n\t" 138 " waitcnt %[nextCNT], %[clockDelay] \n\t" 139 " or dira, %[SCLMask] \n\t" 142 " djnz %[datamask], #" FC_ADDR(
"PutByteLoop%=",
"PutByteStart")
" nr \n\t" 145 " andn dira, %[SDAMask] \n\t" 146 " waitcnt %[nextCNT], %[clockDelay] \n\t" 147 " andn dira, %[SCLMask] \n\t" 148 " waitcnt %[nextCNT], %[clockDelay] \n\t" 149 " mov %[temp], ina \n\t" 150 " and %[SDAMask], %[temp] wz,nr \n\t" 151 " muxz %[result], #1 \n\t" 152 " or dira, %[SCLMask] \n\t" 153 " or dira, %[SDAMask] \n\t" 157 [datamask]
"=&r"(datamask),
158 [result]
"=&r"(result),
159 [nextCNT]
"=&r"(nextCNT),
162 [SDAMask]
"r"(this->m_sda.get_mask()),
163 [SCLMask]
"r"(this->m_scl.get_mask()),
164 [databyte]
"r"(byte),
165 [clockDelay]
"r"(m_clockDelay));
167 return (
bool) result;
179 int datamask, nextCNT, temp;
182 FC_START(
"GetByteStart",
"GetByteEnd")
184 " andn dira, %[SDAMask] \n\t" 185 " mov %[datamask], #256 \n\t" 186 " mov %[result], #0 \n\t" 187 " mov %[nextCNT], cnt \n\t" 188 " add %[nextCNT], %[clockDelay] \n\t" 194 " waitcnt %[nextCNT], %[clockDelay] \n\t" 195 " shr %[datamask], #1 \n\t" 198 " andn dira, %[SCLMask] \n\t" 199 " waitcnt %[nextCNT], %[clockDelay] \n\t" 200 " mov %[temp], ina \n\t" 201 " and %[temp], %[SDAMask] nr,wz \n\t" 202 " muxnz %[result], %[datamask] \n\t" 203 " or dira, %[SCLMask] \n\t" 206 " djnz %[datamask], #" FC_ADDR(
"GetByteLoop%=",
"GetByteStart")
" nr \n\t" 210 " and %[acknowledge], #1 nr,wz \n\t" 212 " muxnz dira, %[SDAMask] \n\t" 213 " waitcnt %[nextCNT], %[clockDelay] \n\t" 214 " andn dira, %[SCLMask] \n\t" 215 " waitcnt %[nextCNT], %[clockDelay] \n\t" 217 " or dira, %[SCLMask] \n\t" 218 " or dira, %[SDAMask] \n\t" 221 [datamask]
"=&r"(datamask),
222 [result]
"=&r"(result),
224 [nextCNT]
"=&r"(nextCNT)
227 [SDAMask]
"r"(this->m_sda.get_mask()),
228 [SCLMask]
"r"(this->m_scl.get_mask()),
229 [acknowledge]
"r"(acknowledge),
230 [clockDelay]
"r"(m_clockDelay));
232 return (uint8_t) result;
239 unsigned int m_clockDelay;
void set_mask(const PropWare::Port::Mask mask)
Utility class to handle general purpose I/O pins.
void start() const
Output a start condition on the I2C bus.
void set_dir_in() const
Set the port for input.
void clear() const
Clear selected output port (set it to 0)
Generic definitions and functions for the Parallax Propeller.
I2CBase(const Pin::Mask sclMask=DEFAULT_SCL_MASK, const Pin::Mask sdaMask=DEFAULT_SDA_MASK, const unsigned int frequency=DEFAULT_FREQUENCY)
Set the IO Pins to float high; Does not require a cog.
void set_dir_out() const
Set the port for output.
void toggle() const
Toggle the output value of a port.
bool send_byte(const uint8_t byte) const
Output a byte on the I2C bus.
void stop() const
Output a stop condition on the I2C bus.
void set() const
Set selected output port high (set all pins to 1)
void set_frequency(const unsigned int frequency)
Set the bus frequency.
Low level I2C driver. Only does the most basic functions that all I2C devices implement.
uint8_t read_byte(const bool acknowledge) const
Get a byte from the bus.