@@ -173,8 +173,65 @@ void attachInterrupt(uint8_t interrupt, void ISR(void), uint8_t mode);
173173void detachInterrupt (uint8_t interrupt);
174174
175175// TODO: issue #26 to track the commanded state here
176- inline void tone (uint8_t _pin, unsigned int frequency, unsigned long duration = 0 ) {}
177- inline void noTone (uint8_t _pin) {}
176+ inline void tone (uint8_t _pin, unsigned int frequency, unsigned long duration = 0 ) { throw " Not Yet Implemented" ; }
177+ inline void noTone (uint8_t _pin) { throw " Not Yet Implemented" ; }
178+ inline uint8_t pulseIn (uint8_t _pin, uint8_t _value, uint32_t _timeout) { throw " Not Yet Implemented" ; }
179+ inline uint8_t pulseIn (uint8_t pin, uint8_t value) { return pulseIn (pin, value, (uint32_t ) 1000000 ); }
180+ inline uint32_t pulseInLong (uint8_t _pin, uint8_t _value, uint32_t _timeout) { throw " Not Yet Implemented" ; }
181+ inline uint32_t pulseInLong (uint8_t pin, uint8_t value) { return pulseInLong (pin, value, (uint32_t ) 1000000 ); }
182+
183+ /* *
184+ * Shifts in a byte of data one bit at a time.
185+ *
186+ * Starts from either the most (i.e. the leftmost) or least (rightmost)
187+ * significant bit. For each bit, the clock pin is pulled high, the next bit is
188+ * read from the data line, and then the clock pin is taken low.
189+ *
190+ * @param dataPin the pin on which to input each bit
191+ * @param clockPin the pin to toggle to signal a read from dataPin
192+ * @param bitOrder which order to shift in the bits; either MSBFIRST or LSBFIRST. B=Bit, not byte
193+ *
194+ * @return The value read
195+ */
196+ inline uint8_t shiftIn (uint8_t dataPin, uint8_t clockPin, bool bitOrder) {
197+ bool mFirst = bitOrder == MSBFIRST;
198+ uint8_t ret = 0x00 ;
199+ for (uint8_t i = 0 , mask = (bitOrder == MSBFIRST ? 0x80 : 0x01 ); i < 8 ; ++i) {
200+ digitalWrite (clockPin, HIGH);
201+ uint8_t setBit = mFirst ? 0x80 : 0x01 ;
202+ uint8_t val = (mFirst ? (setBit >> i) : (setBit << i));
203+ ret = ret | (digitalRead (dataPin) ? val : 0x00 );
204+ digitalWrite (clockPin, LOW);
205+ }
206+ return ret;
207+ }
208+
209+ /* *
210+ * Shifts out a byte of data one bit at a time.
211+ *
212+ * Starts from either the most (i.e. the leftmost) or least (rightmost)
213+ * significant bit. Each bit is written in turn to a data pin, after which a
214+ * clock pin is pulsed (taken high, then low) to indicate that the bit is
215+ * available.
216+ *
217+ * @param dataPin the pin on which to input each bit
218+ * @param clockPin the pin to toggle to signal a write from dataPin
219+ * @param bitOrder which order to shift in the bits; either MSBFIRST or LSBFIRST. B=Bit, not byte
220+ * @param value the data to shift out
221+ *
222+ * @return The value read
223+ */
224+ inline void shiftOut (uint8_t dataPin, uint8_t clockPin, bool bitOrder, uint8_t value) {
225+ bool mFirst = bitOrder == MSBFIRST;
226+ uint8_t ret = 0x00 ;
227+ for (uint8_t i = 0 , mask = (bitOrder == MSBFIRST ? 0x80 : 0x01 ); i < 8 ; ++i) {
228+ uint8_t setBit = mFirst ? 0x80 : 0x01 ;
229+ uint8_t val = (mFirst ? (setBit >> i) : (setBit << i));
230+ digitalWrite (dataPin, (value & val) ? HIGH : LOW);
231+ digitalWrite (clockPin, HIGH);
232+ digitalWrite (clockPin, LOW);
233+ }
234+ }
178235
179236// These definitions allow the following to compile (see issue #193):
180237// https://github.com/arduino-libraries/Ethernet/blob/master/src/utility/w5100.h:341
0 commit comments