diff --git a/avr/cores/microcore/Arduino.h b/avr/cores/microcore/Arduino.h index f39d46d5..6d4a7217 100644 --- a/avr/cores/microcore/Arduino.h +++ b/avr/cores/microcore/Arduino.h @@ -115,38 +115,6 @@ extern "C"{ void loop(void); void yield(void) __attribute__ ((weak, alias("__empty"))); static void __empty() { /* Empty*/ } - - // Constant checks error handler - void badArg(const char*) __attribute__((error(""))); - #define ASSERT_CONST(pin) \ - if(!__builtin_constant_p(pin)) badArg("Pin must be a constant") - - // Check for valid PWM pin (0 .. 5) - __attribute__((always_inline)) - inline void check_valid_digital_pin(uint8_t pin) - { - if(__builtin_constant_p(pin)) - { - if(pin >= NUM_DIGITAL_PINS) - badArg("Digtial pin out of range"); - } - else - badArg("Digital pin must be a constant"); - } - - // Check for valid PWM pin (0 .. 1) - __attribute__((always_inline)) - inline void check_valid_pwm_pin(uint8_t pin) - { - if(__builtin_constant_p(pin)) - { - if(pin > 1) - badArg("PWM pin out of range"); - } - else - badArg("PWM pin must be a constant"); - } - #ifdef __cplusplus } // extern "C" diff --git a/avr/cores/microcore/wiring_digital.c b/avr/cores/microcore/wiring_digital.c index 7f2835a0..4e59029c 100644 --- a/avr/cores/microcore/wiring_digital.c +++ b/avr/cores/microcore/wiring_digital.c @@ -1,10 +1,10 @@ /*** MicroCore - wiring_digital.c *** An Arduino core designed for ATtiny13 -Based on the work done by "smeezekitty" +Based on the work done by "smeezekitty" Modified and maintained by MCUdude https://github.com/MCUdude/MicroCore -This file contains digital related +This file contains digital related functions such as pinMode(), digitalWrite() and digitalRead(). */ @@ -13,11 +13,9 @@ digitalWrite() and digitalRead(). void pinMode(uint8_t pin, uint8_t mode) { - check_valid_digital_pin(pin); - if(mode == OUTPUT) // Pin as output DDRB |= _BV(pin); - + else // Pin as input or input pullup { DDRB &= ~_BV(pin); // Set pin as input @@ -26,11 +24,8 @@ void pinMode(uint8_t pin, uint8_t mode) } } - void digitalWrite(uint8_t pin, uint8_t val) { - check_valid_digital_pin(pin); - if(val) PORTB |= _BV(pin); // Set pin high else @@ -40,7 +35,5 @@ void digitalWrite(uint8_t pin, uint8_t val) uint8_t digitalRead(uint8_t pin) { - check_valid_digital_pin(pin); - return !!(PINB & _BV(pin)); } diff --git a/avr/cores/microcore/wiring_pulse.c b/avr/cores/microcore/wiring_pulse.c index f2c5b285..3f34ad6b 100644 --- a/avr/cores/microcore/wiring_pulse.c +++ b/avr/cores/microcore/wiring_pulse.c @@ -21,13 +21,6 @@ dozen microseconds before the start of the pulse. // However it will only work properly with LTO enabled. uint32_t pulseIn(uint8_t pin, uint8_t state, uint32_t timeout) { - check_valid_digital_pin(pin); - - #if defined(SAFEMODE) - if(pin < 2) - turnOffPWM(c); // If it's a PWM pin, make sure PWM is off - #endif - // Convert the timeout from microseconds to a number of times through // the initial loop; it takes 16 clock cycles per iteration. uint32_t numloops = 0; diff --git a/avr/cores/microcore/wiring_pwm.c b/avr/cores/microcore/wiring_pwm.c index bae6e97e..e0cce6f1 100644 --- a/avr/cores/microcore/wiring_pwm.c +++ b/avr/cores/microcore/wiring_pwm.c @@ -13,19 +13,14 @@ analogWrite(). void turnOffPWM(uint8_t pin) { - check_valid_pwm_pin(pin); - if(pin == 0) TCCR0A &= ~_BV(COM0A1); else TCCR0A &= ~_BV(COM0B1); } - void analogWrite(uint8_t pin, uint8_t val) { - check_valid_pwm_pin(pin); - // Set Timer0 prescaler #if !defined(ENABLE_MICROS) #if defined(PWM_PRESCALER_NONE) // PWM frequency = (F_CPU/256) / 1 @@ -47,7 +42,8 @@ void analogWrite(uint8_t pin, uint8_t val) #endif #endif - pinMode(pin, OUTPUT); + // Set pin to output + DDRB |= _BV(pin); // Handle off condition if(val == 0) diff --git a/avr/cores/microcore/wiring_shift.c b/avr/cores/microcore/wiring_shift.c index 0c8c01dc..5cef5c45 100644 --- a/avr/cores/microcore/wiring_shift.c +++ b/avr/cores/microcore/wiring_shift.c @@ -13,33 +13,23 @@ functions shiftIn() and shiftOut(). uint8_t shiftIn(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder) { - check_valid_digital_pin(dataPin); - check_valid_digital_pin(clockPin); - - #if defined(SAFEMODE) - if(clockPin < 2) - turnOffPWM(clockPin); // If it's a PWM pin, make sure PWM is off - if(dataPin < 2) - turnOffPWM(dataPin); // If it's a PWM pin, make sure PWM is off - #endif - uint8_t value = 0; uint8_t i = 8; do { - digitalWrite(clockPin, HIGH); + PORTB |= _BV(clockPin); if(bitOrder == MSBFIRST) value <<= 1; else value >>= 1; - if(digitalRead(dataPin)) + if(PINB & _BV(dataPin)) { if(bitOrder == MSBFIRST) value |= 0x01; else value |= 0x80; } - digitalWrite(clockPin, LOW); + PORTB &= ~_BV(clockPin); } while(--i); @@ -49,21 +39,11 @@ uint8_t shiftIn(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder) void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t value) { - check_valid_digital_pin(dataPin); - check_valid_digital_pin(clockPin); - const uint8_t datapinMask = _BV(dataPin); const uint8_t clkpinMask = _BV(clockPin); uint8_t i = 8; uint8_t portbits = (PORTB &= ~(datapinMask | clkpinMask)); - #if defined(SAFEMODE) - if(clockPin < 2) - turnOffPWM(clockPin); // If it's a PWM pin, make sure PWM is off - if(dataPin < 2) - turnOffPWM(dataPin); // If it's a PWM pin, make sure PWM is off - #endif - do { if(bitOrder == MSBFIRST)