|
PropWare
3.0.0.229
C++ objects and CMake build system for Parallax Propeller
|
1 #ifndef LIBPROPELLER_I2C_BASE_H_
2 #define LIBPROPELLER_I2C_BASE_H_
6 #define I2C_FLOAT_SCL_HIGH (DIRA &= ~scl_mask_)
7 #define I2C_SET_SCL_LOW (DIRA |= scl_mask_)
8 #define I2C_FLOAT_SDA_HIGH (DIRA &= ~sda_mask_)
9 #define I2C_SET_SDA_LOW (DIRA |= sda_mask_)
32 void Init(
const int scl = 28,
const int sda = 29,
const int frequency = 400000) {
67 clock_delay_ =
CLKFREQ/(2*frequency);
95 int datamask, nextCNT, temp;
98 " fcache #(PutByteEnd - PutByteStart)\n\t"
102 " mov %[datamask], #256 \n\t"
103 " mov %[result], #0 \n\t"
104 " mov %[nextCNT], cnt \n\t"
105 " add %[nextCNT], %[clockDelay] \n\t"
110 " shr %[datamask], #1 \n\t"
111 " and %[datamask], %[databyte] wz,nr \n\t"
112 " muxz dira, %[SDAMask] \n\t"
115 " waitcnt %[nextCNT], %[clockDelay] \n\t"
116 " andn dira, %[SCLMask] \n\t"
117 " waitcnt %[nextCNT], %[clockDelay] \n\t"
118 " or dira, %[SCLMask] \n\t"
121 " djnz %[datamask], #__LMM_FCACHE_START+(PutByteLoop-PutByteStart) nr \n\t"
124 " andn dira, %[SDAMask] \n\t"
125 " waitcnt %[nextCNT], %[clockDelay] \n\t"
126 " andn dira, %[SCLMask] \n\t"
127 " waitcnt %[nextCNT], %[clockDelay] \n\t"
128 " mov %[temp], ina \n\t"
129 " and %[SDAMask], %[temp] wz,nr \n\t"
130 " muxz %[result], #1 \n\t"
131 " or dira, %[SCLMask] \n\t"
132 " or dira, %[SDAMask] \n\t"
133 " jmp __LMM_RET \n\t"
135 " .compress default \n\t"
137 [datamask]
"=&r" (datamask),
138 [result]
"=&r" (result),
139 [nextCNT]
"=&r" (nextCNT),
142 [SDAMask]
"r" (sda_mask_),
143 [SCLMask]
"r" (scl_mask_),
144 [databyte]
"r" (byte),
145 [clockDelay]
"r" (clock_delay_)
159 int datamask, nextCNT, temp;
162 " fcache #(GetByteEnd - GetByteStart)\n\t"
163 " .compress off \n\t"
166 " andn dira, %[SDAMask] \n\t"
167 " mov %[datamask], #256 \n\t"
168 " mov %[result], #0 \n\t"
169 " mov %[nextCNT], cnt \n\t"
170 " add %[nextCNT], %[clockDelay] \n\t"
176 " waitcnt %[nextCNT], %[clockDelay] \n\t"
177 " shr %[datamask], #1 \n\t"
180 " andn dira, %[SCLMask] \n\t"
181 " waitcnt %[nextCNT], %[clockDelay] \n\t"
182 " mov %[temp], ina \n\t"
183 " and %[temp], %[SDAMask] nr,wz \n\t"
184 " muxnz %[result], %[datamask] \n\t"
185 " or dira, %[SCLMask] \n\t"
188 " djnz %[datamask], #__LMM_FCACHE_START+(GetByteLoop-GetByteStart) nr \n\t"
192 " and %[acknowledge], #1 nr,wz \n\t"
194 " muxnz dira, %[SDAMask] \n\t"
195 " waitcnt %[nextCNT], %[clockDelay] \n\t"
196 " andn dira, %[SCLMask] \n\t"
197 " waitcnt %[nextCNT], %[clockDelay] \n\t"
199 " or dira, %[SCLMask] \n\t"
200 " or dira, %[SDAMask] \n\t"
201 " jmp __LMM_RET \n\t"
203 " .compress default \n\t"
206 [datamask]
"=&r" (datamask),
207 [result]
"=&r" (result),
209 [nextCNT]
"=&r" (nextCNT)
212 [SDAMask]
"r" (sda_mask_),
213 [SCLMask]
"r" (scl_mask_),
214 [acknowledge]
"r" (acknowledge),
215 [clockDelay]
"r" (clock_delay_)
223 unsigned int scl_mask_;
224 unsigned int sda_mask_;
232 #endif // LIBPROPELLER_I2C_BASE_H_
#define OUTA
Use to set output pin states when corresponding DIRA bits are 1.
void Init(const int scl=28, const int sda=29, const int frequency=400000)
bool SendByte(const unsigned char byte)
void SetFrequency(const int frequency)
#define CLKFREQ
Returns the current clock frequency.
unsigned char ReadByte(const bool acknowledge)