Buffered Test
Dependencies: ExioBufferdController MCP23S17 mbed-rtos mbed
main.cpp
- Committer:
- ryood
- Date:
- 2016-11-04
- Revision:
- 10:5d1a09afe152
- Parent:
- 9:76d17c5cac87
- Child:
- 11:325c5e9d28e2
File content as of revision 10:5d1a09afe152:
/* * ExioBufferdController Test * * mbed: revison 121 * mbed-rtos: revision 117 * * Created: 2016.11.05 * */ #include "mbed.h" #include "rtos.h" #include "ExioMcp23s17.h" #include "ExioInBuffer.h" #include "ExioBufferedIn.h" #include "ExioBufferedDebounceIn.h" #include "ExioBufferedPinDetect.h" #include "ExioBufferedRotaryEncoder.h" SPI Spi(PC_12, PC_11, PC_10); // SPI3: mosi, miso, sclk //SPI Spi(PA_7, PA_6, PA_5); // SPI1: mosi, miso, sclk // MExioMcp23s17(int hardwareaddress, SPI& spi, PinName nCs, PinName nReset); ExioMcp23s17 Exio(0x00, Spi, PD_2, PA_13); bool state = false; uint8_t count = 0; //------------------------------------------------------------------------------ // Callback functions // void pa6Falled() { state = !state; } void pa7Falled() { count++; } //------------------------------------------------------------------------------ // Test functions // void testExioInBuffer() { printf("*** Test ExioInBuffer ***\r\n"); // Reset MCP23S17 (初期化時にreset()が必要) Exio.reset(); ExioInBuffer exioInBufferA(&Exio, ExioPortA); ExioInBuffer exioInBufferB(&Exio, ExioPortB); exioInBufferA.run(1); exioInBufferB.run(1); while (true) { uint8_t va = exioInBufferA.readPort(); uint8_t vb = exioInBufferB.readPort(); printf("%d %d\r\n", va, vb); //Thread::wait(10); } } void testExioBufferedIn() { printf("*** Test ExioBuffedIn ***\r\n"); // Reset MCP23S17 (初期化時にreset()が必要) Exio.reset(); ExioInBuffer inBufferA(&Exio, ExioPortA); ExioBufferedIn inA[] = { ExioBufferedIn(&inBufferA, 0), ExioBufferedIn(&inBufferA, 1), ExioBufferedIn(&inBufferA, 2), ExioBufferedIn(&inBufferA, 3), ExioBufferedIn(&inBufferA, 4), ExioBufferedIn(&inBufferA, 5), ExioBufferedIn(&inBufferA, 6), ExioBufferedIn(&inBufferA, 7) }; ExioInBuffer inBufferB(&Exio, ExioPortB); ExioBufferedIn inB[] = { ExioBufferedIn(&inBufferB, 0), ExioBufferedIn(&inBufferB, 1), ExioBufferedIn(&inBufferB, 2), ExioBufferedIn(&inBufferB, 3), ExioBufferedIn(&inBufferB, 4), ExioBufferedIn(&inBufferB, 5), ExioBufferedIn(&inBufferB, 6), ExioBufferedIn(&inBufferB, 7) }; inBufferA.run(10); inBufferB.run(10); while (true) { for (int i = 0; i < 8; i++) { int va = inA[i].read(); printf("%d ", va); } putchar(' '); for (int i = 0; i < 8; i++) { int vb = inB[i].read(); printf("%d ", vb); } printf("\r\n"); //Thread::wait(10); } } void testExioBufferedDebounceIn() { printf("*** Test ExioBuffeDebounceIn ***\r\n"); // Reset MCP23S17 (初期化時にreset()が必要) Exio.reset(); ExioInBuffer inBufferA(&Exio, ExioPortA); ExioBufferedDebounceIn inA[] = { ExioBufferedDebounceIn(&inBufferA, 0), ExioBufferedDebounceIn(&inBufferA, 1), ExioBufferedDebounceIn(&inBufferA, 2), ExioBufferedDebounceIn(&inBufferA, 3), ExioBufferedDebounceIn(&inBufferA, 4), ExioBufferedDebounceIn(&inBufferA, 5), ExioBufferedDebounceIn(&inBufferA, 6), ExioBufferedDebounceIn(&inBufferA, 7) }; ExioInBuffer inBufferB(&Exio, ExioPortB); ExioBufferedIn inB[] = { ExioBufferedDebounceIn(&inBufferB, 0), ExioBufferedDebounceIn(&inBufferB, 1), ExioBufferedDebounceIn(&inBufferB, 2), ExioBufferedDebounceIn(&inBufferB, 3), ExioBufferedDebounceIn(&inBufferB, 4), ExioBufferedDebounceIn(&inBufferB, 5), ExioBufferedDebounceIn(&inBufferB, 6), ExioBufferedDebounceIn(&inBufferB, 7) }; // Start Timers inBufferA.run(10); inBufferB.run(10); for (int i = 0; i < 8; i++) { inA[i].set_debounce_us(10000); inA[i].set_debounce_us(10000); } while (true) { for (int i = 0; i < 8; i++) { int va = inA[i].read(); printf("%d ", va); } putchar(' '); for (int i = 0; i < 8; i++) { int vb = inB[i].read(); printf("%d ", vb); } printf("\r\n"); //Thread::wait(10); } } void testExioBufferedPinDetect() { printf("*** Test ExioBufferedPinDetect ***\r\n"); // Reset MCP23S17 (初期化時にreset()が必要) Exio.reset(); ExioInBuffer inBufferA(&Exio, ExioPortA); ExioBufferedPinDetect pinA6(&inBufferA, 6); ExioBufferedPinDetect pinA7(&inBufferA, 7); // assign callback functions pinA6.attach_asserted(&pa6Falled); pinA6.setAssertValue(0); pinA7.attach_asserted(&pa7Falled); pinA7.setAssertValue(0); // Start Timers inBufferA.run(5); pinA6.setSampleFrequency(10000); pinA7.setSampleFrequency(10000); while (true) { printf("%d %d\r\n", state, count); } } void testExioBufferedRotaryEncoder() { printf("*** Test ExioBufferedRotaryEncoder ***\r\n"); // Reset MCP23S17 (初期化時にreset()が必要) Exio.reset(); ExioInBuffer inBufferA(&Exio, ExioPortA); ExioBufferedRotaryEncoder re1(&inBufferA, 0, 1); // Start Timers inBufferA.run(5); re1.setInterval(1000); while (true) { int v = re1.getVal(); printf("%d\r\n", v); } } int main() { //testExioInBuffer(); //testExioBufferedIn(); //testExioBufferedDebounceIn(); //testExioBufferedRotaryEncoder(); //testExioBufferedPinDetect(); printf("*** Test ExioBufferedContoroller ***\r\n"); // Reset MCP23S17 (初期化時にreset()が必要) Exio.reset(); // PinDetect ExioInBuffer inBufferA(&Exio, ExioPortA); ExioBufferedPinDetect pinA6(&inBufferA, 6); ExioBufferedPinDetect pinA7(&inBufferA, 7); // assign callback functions pinA6.attach_asserted(&pa6Falled); pinA6.setAssertValue(0); pinA7.attach_asserted(&pa7Falled); pinA7.setAssertValue(0); // DebounceIn ExioInBuffer inBufferB(&Exio, ExioPortB); ExioBufferedDebounceIn inB[] = { ExioBufferedDebounceIn(&inBufferB, 0), ExioBufferedDebounceIn(&inBufferB, 1), ExioBufferedDebounceIn(&inBufferB, 2), ExioBufferedDebounceIn(&inBufferB, 3), ExioBufferedDebounceIn(&inBufferB, 4), ExioBufferedDebounceIn(&inBufferB, 5), ExioBufferedDebounceIn(&inBufferB, 6), ExioBufferedDebounceIn(&inBufferB, 7) }; // Start Timers for polling MCP23S17 inBufferA.run(5); inBufferB.run(10); // Start Timers for PinDetect pinA6.setSampleFrequency(10000); pinA7.setSampleFrequency(10000); // Start Timers for DebounceIn for (int i = 0; i < 8; i++) { inB[i].set_debounce_us(10000); inB[i].set_debounce_us(10000); } while(true) { for (int i = 0; i < 8; i++) { int va = inB[i].read(); printf("%d ", va); } printf(" %d %d \r\n", state, count); } }