From ebea46c98da8400362c9de49986184fa94ff1457 Mon Sep 17 00:00:00 2001 From: hathach Date: Thu, 3 Aug 2017 11:49:27 +0700 Subject: [PATCH] port SoftwareSerial close #62 - can receive data, and sending --- cores/nRF5/WInterrupts.c | 10 +++++++--- cores/nRF5/WInterrupts.h | 4 +++- cores/nRF5/delay.h | 8 ++++---- libraries/SoftwareSerial/SoftwareSerial.cpp | 4 ++-- libraries/SoftwareSerial/SoftwareSerial.h | 9 --------- .../SoftwareSerialExample/SoftwareSerialExample.ino | 6 +++--- 6 files changed, 19 insertions(+), 22 deletions(-) diff --git a/cores/nRF5/WInterrupts.c b/cores/nRF5/WInterrupts.c index 59cc3cb4..b3c6c357 100644 --- a/cores/nRF5/WInterrupts.c +++ b/cores/nRF5/WInterrupts.c @@ -49,8 +49,10 @@ static void __initialize() /* * \brief Specifies a named Interrupt Service Routine (ISR) to call when an interrupt occurs. * Replaces any previous function that was attached to the interrupt. + * + * \return Interrupt Mask */ -void attachInterrupt(uint32_t pin, voidFuncPtr callback, uint32_t mode) +int attachInterrupt(uint32_t pin, voidFuncPtr callback, uint32_t mode) { if (!enabled) { __initialize(); @@ -58,7 +60,7 @@ void attachInterrupt(uint32_t pin, voidFuncPtr callback, uint32_t mode) } if (pin >= PINS_COUNT) { - return; + return 0; } pin = g_ADigitalPinMap[pin]; @@ -95,9 +97,11 @@ void attachInterrupt(uint32_t pin, voidFuncPtr callback, uint32_t mode) NRF_GPIOTE->INTENSET = (1 << ch); - break; + return (1 << ch); } } + + return 0; } /* diff --git a/cores/nRF5/WInterrupts.h b/cores/nRF5/WInterrupts.h index 5d2b24a0..a8bdd9e0 100644 --- a/cores/nRF5/WInterrupts.h +++ b/cores/nRF5/WInterrupts.h @@ -39,8 +39,10 @@ typedef void (*voidFuncPtr)(void); /* * \brief Specifies a named Interrupt Service Routine (ISR) to call when an interrupt occurs. * Replaces any previous function that was attached to the interrupt. + * + * \return Interrupt Mask */ -void attachInterrupt(uint32_t pin, voidFuncPtr callback, uint32_t mode); +int attachInterrupt(uint32_t pin, voidFuncPtr callback, uint32_t mode); /* * \brief Turns off the given interrupt. diff --git a/cores/nRF5/delay.h b/cores/nRF5/delay.h index 586df81d..862d5d8d 100644 --- a/cores/nRF5/delay.h +++ b/cores/nRF5/delay.h @@ -66,10 +66,10 @@ extern void delay( uint32_t dwMs ); static __inline__ void delayMicroseconds( uint32_t ) __attribute__((always_inline, unused)) ; static __inline__ void delayMicroseconds( uint32_t usec ) { - if ( usec == 0 ) - { - return ; - } +// if ( usec == 0 ) +// { +// return ; +// } nrf_delay_us(usec); } diff --git a/libraries/SoftwareSerial/SoftwareSerial.cpp b/libraries/SoftwareSerial/SoftwareSerial.cpp index 4caefc8c..cd320929 100644 --- a/libraries/SoftwareSerial/SoftwareSerial.cpp +++ b/libraries/SoftwareSerial/SoftwareSerial.cpp @@ -109,7 +109,7 @@ bool SoftwareSerial::stopListening() void SoftwareSerial::end() { - stopListening(); + stopListening(); } int SoftwareSerial::read() @@ -326,4 +326,4 @@ void SoftwareSerial::setRX(uint8_t rx) _receiveBitMask = digitalPinToBitMask(rx); NRF_GPIO_Type * port = digitalPinToPort(rx); _receivePortRegister = portInputRegister(port); -} \ No newline at end of file +} diff --git a/libraries/SoftwareSerial/SoftwareSerial.h b/libraries/SoftwareSerial/SoftwareSerial.h index da0eada4..ae1fc08f 100644 --- a/libraries/SoftwareSerial/SoftwareSerial.h +++ b/libraries/SoftwareSerial/SoftwareSerial.h @@ -91,13 +91,4 @@ public: static inline void handle_interrupt() __attribute__((__always_inline__)); }; -// Arduino 0012 workaround -#undef int -#undef char -#undef long -#undef byte -#undef float -#undef abs -#undef round - #endif diff --git a/libraries/SoftwareSerial/examples/SoftwareSerialExample/SoftwareSerialExample.ino b/libraries/SoftwareSerial/examples/SoftwareSerialExample/SoftwareSerialExample.ino index 4e179b7f..a1598b66 100644 --- a/libraries/SoftwareSerial/examples/SoftwareSerialExample/SoftwareSerialExample.ino +++ b/libraries/SoftwareSerial/examples/SoftwareSerialExample/SoftwareSerialExample.ino @@ -5,8 +5,8 @@ Receives from software serial, sends to hardware serial. The circuit: - * RX is digital pin 9 (connect to TX of other device) - * TX is digital pin 10 (connect to RX of other device) + * RX is digital pin A0 (connect to TX of other device) + * TX is digital pin A1 (connect to RX of other device) This example code is in the public domain. @@ -14,7 +14,7 @@ #include -SoftwareSerial mySerial(9, 10); // RX, TX +SoftwareSerial mySerial(A0, A1); // RX, TX void setup()