Multi Module Board Definition Updates (#133)

This commit is contained in:
Ben Lye
2017-12-20 11:31:20 +00:00
committed by GitHub
parent 835cc3d0a2
commit b3eccf55ba
149 changed files with 2540 additions and 4467 deletions

View File

@@ -1,5 +1,6 @@
#include <wiring_pulse.h>
#include "boards.h"
#include "variant.h"
/* Measures the length (in microseconds) of a pulse on the pin; state is HIGH
* or LOW, the type of pulse to measure. Works on pulses from 2-3 microseconds
* to 3 minutes in length, but must be called at least a few dozen microseconds
@@ -28,13 +29,13 @@
*/
uint32_t pulseIn( uint32_t pin, uint32_t state, uint32_t timeout )
{
// cache the port and bit of the pin in order to speed up the
// cache the IDR address and bit of the pin in order to speed up the
// pulse width measuring loop and achieve finer resolution. calling
// digitalRead() instead yields much coarser resolution.
gpio_dev *dev=PIN_MAP[pin].gpio_device;
uint32_t bit = (1U << PIN_MAP[pin].gpio_bit);
__io uint32_t * const idr = portInputRegister(digitalPinToPort(pin));
const uint32_t bit = digitalPinToBitMask(pin);
const uint32_t stateMask = (state ? bit:0);
uint32_t width = 0; // keep initialization out of time critical area
@@ -45,23 +46,23 @@ uint32_t pulseIn( uint32_t pin, uint32_t state, uint32_t timeout )
volatile uint32_t dummyWidth=0;
// wait for any previous pulse to end
while ( (dev->regs->IDR & bit) == bit) {
while ((*idr & bit) == stateMask) {
if (numloops++ == maxloops) {
return 0;
}
dummyWidth++;
dummyWidth++;
}
// wait for the pulse to start
while ((dev->regs->IDR & bit) != bit) {
while ((*idr & bit) != stateMask) {
if (numloops++ == maxloops) {
return 0;
}
dummyWidth++;
dummyWidth++;
}
// wait for the pulse to stop
while ((dev->regs->IDR & bit) == bit) {
while ((*idr & bit) == stateMask) {
if (numloops++ == maxloops) {
return 0;
}

View File

@@ -80,10 +80,13 @@ void pinMode(uint8 pin, WiringPinMode mode) {
gpio_set_mode(PIN_MAP[pin].gpio_device, PIN_MAP[pin].gpio_bit, outputMode);
if (PIN_MAP[pin].timer_device != NULL) {
/* Enable/disable timer channels if we're switching into or
* out of PWM. */
if ( pwm ) { // we're switching into PWM, enable timer channels
timer_set_mode(PIN_MAP[pin].timer_device,
PIN_MAP[pin].timer_channel,
pwm ? TIMER_PWM : TIMER_DISABLED);
TIMER_PWM );
} else { // disable channel output in non pwm-Mode
timer_cc_disable(PIN_MAP[pin].timer_device,
PIN_MAP[pin].timer_channel);
}
}
}