Skip to content

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
  • Loading branch information
hathach committed May 19, 2016
2 parents f7aedf6 + 6c0a058 commit f83b149
Show file tree
Hide file tree
Showing 22 changed files with 46,824 additions and 46,334 deletions.
10 changes: 9 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
# Version 0.5.x (In Progress)
# 0.5.5 (Work In Progress)

# 0.5.2

- Add Servo library suport
- Fix issue where 0xff is misinterpreted as EOF with USBSerial
- Fix EXT GPIO interrupt conflict between Featherlib & Arduino
- Fix #32 PWM only work after 3-5 minutes
- Fix compiling issues with existing library

# 0.5.1

Expand Down
23 changes: 7 additions & 16 deletions examples/Hardware/PWM/Fading/Fading.ino
Original file line number Diff line number Diff line change
Expand Up @@ -18,36 +18,27 @@

#include <adafruit_feather.h>

void setup() {
for(int i=0; i<BOARD_NR_PWM_PINS; i++)
{
pinMode(boardPWMPins[i], PWM); // setup the pin as PWM
}
}
const int ledPin = PA15;

void dim(uint16_t value)
{
for(int i=0; i<BOARD_NR_PWM_PINS; i++)
{
pwmWrite(boardPWMPins[i], value);
}
void setup() {
pinMode(ledPin, PWM); // setup the pin as PWM
}

void loop() {
// Fade in from min to max in increments of 1280 points:
for (int fadeValue = 0; fadeValue <= 65535; fadeValue += 1280) {
// Sets the value (range from 0 to 65535):
//pwmWrite(ledPin, fadeValue);
dim(fadeValue);
pwmWrite(ledPin, fadeValue);

// Wait for 30 milliseconds to see the dimming effect:
delay(30);
}

// Fade out from max to min in increments of 1280 points:
for (int fadeValue = 65535 ; fadeValue >= 0; fadeValue -= 1280) {
// Sets the value (range from 0 to 1280):
//pwmWrite(ledPin, fadeValue);
dim(fadeValue);
pwmWrite(ledPin, fadeValue);

// Wait for 30 milliseconds to see the dimming effect:
delay(30);
}
Expand Down
28 changes: 28 additions & 0 deletions examples/Hardware/PWM/Knob/Knob.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
Controlling a servo position using a potentiometer (variable resistor)
by Michal Rinott <http://people.interaction-ivrea.it/m.rinott>
modified on 8 Nov 2013
by Scott Fitzgerald
http://www.arduino.cc/en/Tutorial/Knob
*/

#include <Servo.h>

Servo myservo; // create servo object to control a servo

int potpin = 0; // analog pin used to connect the potentiometer
int pin = PA15;
int val; // variable to read the value from the analog pin

void setup() {
myservo.attach(pin); // attaches the servo on pin 9 to the servo object
}

void loop() {
val = analogRead(potpin); // reads the value of the potentiometer (value between 0 and 1023)
val = map(val, 0, 1023, 0, 180); // scale it to use it with the servo (value between 0 and 180)
myservo.write(val); // sets the servo position according to the scaled value
delay(15); // waits for the servo to get there
}

33 changes: 33 additions & 0 deletions examples/Hardware/PWM/Sweep/Sweep.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/* Sweep
by BARRAGAN <http://barraganstudio.com>
This example code is in the public domain.
modified 8 Nov 2013
by Scott Fitzgerald
http://www.arduino.cc/en/Tutorial/Sweep
*/

#include <Servo.h>

Servo myservo; // create servo object to control a servo
// twelve servo objects can be created on most boards

int pos = 0; // variable to store the servo position
int pin = PA15;

void setup() {
myservo.attach(pin); // attaches the servo on pin 9 to the servo object
}

void loop() {
for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
// in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
}

13 changes: 10 additions & 3 deletions examples/Hardware/UART/UART.ino
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,30 @@

#include <Arduino.h>

const int baudrate = 115200;

/**************************************************************************/
/*!
@brief The setup function runs once when reset the board
*/
/**************************************************************************/
void setup()
{
Serial.begin (115200); // USB monitor
Serial1.begin(115200); // HW UART1
Serial2.begin(115200); // HW UART2
Serial.begin (baudrate); // USB monitor
Serial1.begin(baudrate); // HW UART1
Serial2.begin(baudrate); // HW UART2

// wait for the serial port to connect. Needed for native USB port only.
while (!Serial) delay(1);

Serial.println ("UART demo: Serial Monitor");
Serial.printf ("Badurate : %d\r\n", baudrate);

Serial1.println("UART demo: HWUART1");
Serial1.printf ("Badurate : %d\r\n", baudrate);

Serial2.println("UART demo: HWUART2");
Serial2.printf ("Badurate : %d\r\n", baudrate);
}

void printAll(char ch)
Expand Down
4 changes: 4 additions & 0 deletions stm32/cores/maple/Arduino.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@
#endif

#include "variant.h"

#define clockCyclesPerMicrosecond() CYCLES_PER_MICROSECOND
#define clockCyclesToMicroseconds(a) ( (a) / clockCyclesPerMicrosecond() )
#define microsecondsToClockCycles(a) ( (a) * clockCyclesPerMicrosecond() )
7 changes: 5 additions & 2 deletions stm32/cores/maple/boards.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,23 +99,26 @@ static void timerDefaultConfig(timer_dev *dev) {
regs->PSC = 1;
regs->SR = 0;
regs->DIER = 0;
regs->EGR = TIMER_EGR_UG;
// regs->EGR = TIMER_EGR_UG;

switch (dev->type) {
case TIMER_ADVANCED:
regs->BDTR = TIMER_BDTR_MOE | TIMER_BDTR_LOCK_OFF;
// fall-through
case TIMER_GENERAL:
timer_set_reload(dev, full_overflow);

#if 0 // disable default mode is PWM !!!
for (int channel = 1; channel <= 4; channel++) {
timer_set_compare(dev, channel, half_duty);
timer_oc_set_mode(dev, channel, TIMER_OC_MODE_PWM_1, TIMER_OC_PE);
}
#endif
// fall-through
case TIMER_BASIC:
break;
}

// UG must be placed after reload to take affect
regs->EGR = TIMER_EGR_UG;
timer_resume(dev);
}
45 changes: 42 additions & 3 deletions stm32/cores/maple/libmaple/SPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
#include "wirish.h"
#include "boards.h"

ATTR_UNUSED uint8_t SPCR;

struct spi_pins {
int8_t nss;
int8_t sck;
Expand Down Expand Up @@ -96,9 +98,9 @@ void HardwareSPI::begin(void)
enable_device(this->spi_d, true, SPI_BAUD_PCLK_DIV_8, SPI_FRAME_MSB, (spi_mode) SPI_MODE0);
}

void HardwareSPI::beginTransaction(SPISettings settings)
void HardwareSPI::reconfigure(void)
{
uint32_t baud = settings.baud_control;
uint32_t baud = _setting.baud_control;

// SPI3 has slower speed than SPI1
if (this->spi_d == SPI3_F2 && baud > 0)
Expand All @@ -107,7 +109,44 @@ void HardwareSPI::beginTransaction(SPISettings settings)
}

spi_reconfigure(this->spi_d, SPI_DFF_8_BIT | SPI_SW_SLAVE | SPI_SOFT_SS |
settings.bitOrder | baud | SPI_CR1_MSTR | settings.dataMode);
_setting.bitOrder | baud | SPI_CR1_MSTR | _setting.dataMode);
}

void HardwareSPI::beginTransaction(SPISettings settings)
{
_setting.baud_control = settings.baud_control;
_setting.bitOrder = settings.bitOrder;
_setting.dataMode = settings.dataMode;

reconfigure();
}

void HardwareSPI::setClockDivider(uint8_t clockDivider)
{
if (_setting.baud_control != clockDivider)
{
_setting.baud_control = clockDivider;
reconfigure();
}
}

void HardwareSPI::setBitOrder(uint8_t bitOrder)
{
bitOrder = ((bitOrder == MSBFIRST) ? SPI_FRAME_MSB : SPI_FRAME_LSB);
if (_setting.bitOrder != bitOrder)
{
_setting.bitOrder = bitOrder;
reconfigure();
}
}

void HardwareSPI::setDataMode(uint8_t dataMode)
{
if (_setting.dataMode != dataMode)
{
_setting.dataMode = dataMode;
reconfigure();
}
}

void HardwareSPI::endTransaction(void)
Expand Down
23 changes: 18 additions & 5 deletions stm32/cores/maple/libmaple/SPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,15 @@
#define SPI_MODE2 SPI_MODE_2
#define SPI_MODE3 SPI_MODE_3

#define SPI_CLOCK_DIV2 SPI_BAUD_PCLK_DIV_2
#define SPI_CLOCK_DIV4 SPI_BAUD_PCLK_DIV_4
#define SPI_CLOCK_DIV8 SPI_BAUD_PCLK_DIV_8
#define SPI_CLOCK_DIV16 SPI_BAUD_PCLK_DIV_16
#define SPI_CLOCK_DIV32 SPI_BAUD_PCLK_DIV_32
#define SPI_CLOCK_DIV64 SPI_BAUD_PCLK_DIV_64
#define SPI_CLOCK_DIV128 SPI_BAUD_PCLK_DIV_128
#define SPI_CLOCK_DIV256 SPI_BAUD_PCLK_DIV_256

#define SPI_HAS_TRANSACTION 1

class SPISettings {
Expand Down Expand Up @@ -93,6 +102,9 @@ class HardwareSPI {
private:
spi_dev *spi_d;
int8_t _ss_pin;
SPISettings _setting;

void reconfigure(void);

public:
/**
Expand All @@ -119,11 +131,9 @@ class HardwareSPI {
void attachInterrupt(void) { }
void detachInterrupt(void) { }

#if 0
void setClockDivider(uint8_t clockDivider) { _clockDivider = clockDivider; }
void setBitOrder(BitOrder bitOrder) { _bitOrder = bitOrder; }
void setDataMode(uint8_t dataMode) { _dataMode = dataMode; }
#endif
void setClockDivider(uint8_t clockDivider);
void setBitOrder(uint8_t bitOrder);
void setDataMode(uint8_t dataMode);

#if 0
void beginSlave(uint32_t bitOrder, uint32_t mode);
Expand All @@ -134,5 +144,8 @@ class HardwareSPI {

extern HardwareSPI SPI;

// Fix Compiler issue with sensor library
extern uint8_t SPCR;

#endif

2 changes: 1 addition & 1 deletion stm32/cores/maple/libmaple/adafruit_featherlib.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@

//------------- Arduino Shared Structure -------------//
#define CFG_ARDUINO_CODE_MAGIC 0xDEC0DED
#define CFG_ARDUINO_CODE_VERSION "0.5.1"
#define CFG_ARDUINO_CODE_VERSION "0.5.2"

#define RESERVED_ XSTRING_CONCAT_(_rerserved, __LINE__)

Expand Down
4 changes: 2 additions & 2 deletions stm32/cores/maple/libmaple/dac.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@
* @brief DAC peripheral routines.
*/

dac_dev dac = {
dac_dev _dac = {
.regs = DAC_BASE,
};
/** DAC device. */
const dac_dev *DAC = &dac;
const dac_dev *DAC = &_dac;

/**
* @brief Initialize the digital to analog converter
Expand Down
5 changes: 5 additions & 0 deletions stm32/cores/maple/libmaple/delay.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
#ifndef _DELAY_H_
#define _DELAY_H_

// To stay compatible with AVR
#define _delay_us delay_us
#define _delay_ms delay

/**
* @brief Delay the given number of microseconds.
*
Expand Down Expand Up @@ -40,5 +44,6 @@ static inline void delay_ns100(uint32 us) {
: [us] "r" (us)
: "r0");
}

#endif

43 changes: 43 additions & 0 deletions stm32/cores/maple/libmaple/util/delay.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**************************************************************************/
/*!
@file delay.h
@author hathach
@section LICENSE
Software License Agreement (BSD License)
Copyright (c) 2016, Adafruit Industries (adafruit.com)
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. Neither the name of the copyright holders nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/**************************************************************************/

#ifndef _UTIL_DELAY_H_
#define _UTIL_DELAY_H_

// This file exist for Arduino AVR comaptible compilation only
#include "../delay.h"

#endif /* _UTIL_DELAY_H_ */
Loading

0 comments on commit f83b149

Please sign in to comment.