Skip to content

Sync release candidate #251

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
Aug 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cores/arduino/am_sdk_ap3/mcu/apollo3/hal/am_hal_uart.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,8 @@ am_hal_uart_transfer_t;

// Flow control
#define AM_HAL_UART_FLOW_CTRL_NONE 0
#define AM_HAL_UART_FLOW_CTRL_CTS_ONLY UART_CR_CTSEN_Msk
#define AM_HAL_UART_FLOW_CTRL_RTS_ONLY UART_CR_RTSEN_Msk
#define AM_HAL_UART_FLOW_CTRL_CTS_ONLY UART0_CR_CTSEN_Msk
#define AM_HAL_UART_FLOW_CTRL_RTS_ONLY UART0_CR_RTSEN_Msk
#define AM_HAL_UART_FLOW_CTRL_RTS_CTS (UART0_CR_CTSEN_Msk | \
UART0_CR_RTSEN_Msk)
// FIFO enable/disable.
Expand Down
28 changes: 24 additions & 4 deletions cores/arduino/ard_sup/analog/ap3_analog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,27 @@ uint16_t analogRead(uint8_t pinNumber)
{
if (ap3_analog_configure_map[indi].isAnalog == false)
{
if (ap3_set_pin_to_analog(pinNumber) != AP3_OK)
if (padNumber == AP3_ADC_DIFF0_PAD)
{
ap3_err_t retval = AP3_ERR;
retval = ap3_set_pin_to_analog(ap3_gpio_pad2pin(12));
retval = ap3_set_pin_to_analog(ap3_gpio_pad2pin(13));
if (retval != AP3_OK)
{
return 0; //Error
}
}
else if (padNumber == AP3_ADC_DIFF1_PAD)
{
ap3_err_t retval = AP3_ERR;
retval = ap3_set_pin_to_analog(ap3_gpio_pad2pin(14));
retval = ap3_set_pin_to_analog(ap3_gpio_pad2pin(15));
if (retval != AP3_OK)
{
return 0; //Error
}
}
else if (ap3_set_pin_to_analog(pinNumber) != AP3_OK)
{
//Serial.println("Error - set pin to analog");
return 0; //Error
Expand Down Expand Up @@ -335,13 +355,12 @@ ap3_err_t ap3_adc_setup()
}

//Set function of pin to analog input
//TODO Support differential pairs 0/1
ap3_err_t ap3_set_pin_to_analog(uint8_t pinNumber)
{
ap3_err_t retval = AP3_ERR;

uint8_t funcsel = 0;
am_hal_gpio_pincfg_t pincfg = AP3_PINCFG_INPUT;

retval = ap3_analog_pad_funcsel(ap3_gpio_pin2pad(pinNumber), &funcsel);

if (retval != AP3_OK)
Expand All @@ -350,10 +369,11 @@ ap3_err_t ap3_set_pin_to_analog(uint8_t pinNumber)
}
pincfg.uFuncSel = funcsel; // set the proper function select option for this instance/pin/type combination
pinMode(pinNumber, pincfg, &retval);

return retval;
}

//Given pin number, assign ADC function
//Given pad number, get ADC function
ap3_err_t ap3_analog_pad_funcsel(ap3_gpio_pad_t padNumber, uint8_t *funcsel)
{
ap3_err_t retval = AP3_ERR;
Expand Down
6 changes: 4 additions & 2 deletions cores/arduino/ard_sup/analog/ap3_analog_structures.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ const ap3_analog_pad_map_elem_t ap3_analog_map[AP3_ANALOG_PADS] = {
{.pad = 11, .funcsel = AM_HAL_PIN_11_ADCSE2},
{.pad = 12, .funcsel = AM_HAL_PIN_12_ADCD0NSE9},
{.pad = 13, .funcsel = AM_HAL_PIN_13_ADCD0PSE8},
{.pad = 14, .funcsel = AM_HAL_PIN_14_ADCD1P},
{.pad = 15, .funcsel = AM_HAL_PIN_15_ADCD1N},
{.pad = 16, .funcsel = AM_HAL_PIN_16_ADCSE0},
{.pad = 29, .funcsel = AM_HAL_PIN_29_ADCSE1},
{.pad = 31, .funcsel = AM_HAL_PIN_31_ADCSE3},
Expand All @@ -50,8 +52,8 @@ ap3_analog_configure_map_elem_t ap3_analog_configure_map[AP3_ANALOG_CHANNELS] =
{.pad = 33, .isAnalog = false},
{.pad = 34, .isAnalog = false},
{.pad = 35, .isAnalog = false},
{.pad = AP3_ADC_DIFF0_PAD, .isAnalog = true},
{.pad = AP3_ADC_DIFF1_PAD, .isAnalog = true},
{.pad = AP3_ADC_DIFF0_PAD, .isAnalog = false},
{.pad = AP3_ADC_DIFF1_PAD, .isAnalog = false},
{.pad = AP3_ADC_TEMP_PAD, .isAnalog = true},
{.pad = AP3_ADC_DIV3_PAD, .isAnalog = true},
{.pad = AP3_ADC_VSS_PAD, .isAnalog = true},
Expand Down
2 changes: 1 addition & 1 deletion cores/arduino/ard_sup/ap3_analog_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ SOFTWARE.
#ifndef _AP3_ANALOG_TYPES_H_
#define _AP3_ANALOG_TYPES_H_

#define AP3_ANALOG_PADS 10
#define AP3_ANALOG_PADS 12
#define AP3_ANALOG_CHANNELS 15

enum EXTRA_ADC_PADS
Expand Down
25 changes: 13 additions & 12 deletions cores/arduino/ard_sup/ap3_gpio.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,25 +35,26 @@ extern const am_hal_gpio_pincfg_t g_AM_HAL_GPIO_OPEN_DRAIN_WITH_READ_12;
extern const am_hal_gpio_pincfg_t g_AM_HAL_GPIO_INPUT_PULLDOWN;

// macros pointing to internal apollo3 GPIO pincfg structures
#define AP3_PINCFG_INPUT (g_AM_HAL_GPIO_INPUT)
#define AP3_PINCFG_OUTPUT (g_AM_HAL_GPIO_OUTPUT_WITH_READ_12)
#define AP3_PINCFG_INPUT_PULLUP (g_AM_HAL_GPIO_INPUT_PULLUP)
#define AP3_PINCFG_INPUT_PULLDOWN (g_AM_HAL_GPIO_INPUT_PULLDOWN)
#define AP3_PINCFG_OPEN_DRAIN (g_AM_HAL_GPIO_OPEN_DRAIN_WITH_READ_12)
#define AP3_PINCFG_TRISTATE (g_AM_HAL_GPIO_TRISTATE)
#define AP3_PINCFG_INPUT (g_AM_HAL_GPIO_INPUT)
#define AP3_PINCFG_OUTPUT (g_AM_HAL_GPIO_OUTPUT_WITH_READ_12)
#define AP3_PINCFG_INPUT_PULLUP (g_AM_HAL_GPIO_INPUT_PULLUP)
#define AP3_PINCFG_INPUT_PULLDOWN (g_AM_HAL_GPIO_INPUT_PULLDOWN)
#define AP3_PINCFG_OPEN_DRAIN (g_AM_HAL_GPIO_OPEN_DRAIN_WITH_READ_12)
#define AP3_PINCFG_TRISTATE (g_AM_HAL_GPIO_TRISTATE)

// constants for Arduino pin modes
#define INPUT (0x00)
#define OUTPUT (0x01)
#define INPUT_PULLUP (0x02)
#define INPUT_PULLDOWN (0x03)
#define OPEN_DRAIN (0x04)
#define TRISTATE (0x05)
#define INPUT (0x00)
#define OUTPUT (0x01)
#define INPUT_PULLUP (0x02)
#define INPUT_PULLDOWN (0x03)
#define OPEN_DRAIN (0x04)
#define TRISTATE (0x05)

#define AP3_GPIO_MAX_PADS (50)
#define AP3_GPIO_IS_VALID(pad) ((pad >= 0) && (pad < AP3_GPIO_MAX_PADS))

extern ap3_gpio_pad_t ap3_gpio_pin2pad(ap3_gpio_pin_t pin);
extern ap3_gpio_pin_t ap3_gpio_pad2pin(ap3_gpio_pad_t pad);
#define AP3_GPIO_PAD_UNUSED (255)

#define AP3_GPIO_DEFAULT_PINCFG AP3_GPIO_PINCFG_NULL
Expand Down
1 change: 1 addition & 0 deletions cores/arduino/ard_sup/ard_supers/HardwareSerial.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ class HardwareSerial : public Stream
virtual int read(void) = 0;
virtual void flush(void) = 0;
virtual size_t write(uint8_t) = 0;
using Print::write; // pull in write(str) and write(buf, size) from Print
virtual operator bool() = 0;
};

Expand Down
10 changes: 10 additions & 0 deletions cores/arduino/ard_sup/gpio/ap3_gpio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ ap3_gpio_pad_t ap3_gpio_pin2pad(ap3_gpio_pin_t pin)
return ap3_variant_pinmap[pin];
}

ap3_gpio_pin_t ap3_gpio_pad2pin(ap3_gpio_pad_t pad)
{
for (int x = 0; x < AP3_VARIANT_NUM_PINS; x++)
{
if (ap3_variant_pinmap[x] == pad)
return (x);
}
return (AP3_GPIO_PAD_UNUSED);
}

typedef void (*voidFuncPtr)(void);
typedef void (*voidFuncPtrArg)(void *);
typedef struct
Expand Down
20 changes: 18 additions & 2 deletions cores/arduino/ard_sup/uart/ap3_uart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,22 @@ ap3_err_t Uart::set_config(HardwareSerial_Config_e HWSconfig)
retval = AP3_INVALID_ARG;
break;
}

//Setup flow control
_config.ui32FlowControl = AM_HAL_UART_FLOW_CTRL_NONE;
if(_pinRTS != AP3_UART_PIN_UNUSED && _pinCTS != AP3_UART_PIN_UNUSED)
{
_config.ui32FlowControl = AM_HAL_UART_FLOW_CTRL_RTS_CTS;
}
else if(_pinRTS != AP3_UART_PIN_UNUSED)
{
_config.ui32FlowControl = AM_HAL_UART_FLOW_CTRL_RTS_ONLY;
}
else if(_pinCTS != AP3_UART_PIN_UNUSED)
{
_config.ui32FlowControl = AM_HAL_UART_FLOW_CTRL_CTS_ONLY;
}

return retval;
}

Expand Down Expand Up @@ -375,7 +391,7 @@ ap3_err_t Uart::_begin(void)

if (_pinRTS != AP3_UART_PIN_UNUSED)
{
retval = ap3_uart_pad_funcsel(_instance, AP3_UART_TX, ap3_gpio_pin2pad(_pinRTS), &funcsel);
retval = ap3_uart_pad_funcsel(_instance, AP3_UART_RTS, ap3_gpio_pin2pad(_pinRTS), &funcsel);
if (retval != AP3_OK)
{
return retval;
Expand All @@ -391,7 +407,7 @@ ap3_err_t Uart::_begin(void)

if (_pinCTS != AP3_UART_PIN_UNUSED)
{
retval = ap3_uart_pad_funcsel(_instance, AP3_UART_RX, ap3_gpio_pin2pad(_pinCTS), &funcsel);
retval = ap3_uart_pad_funcsel(_instance, AP3_UART_CTS, ap3_gpio_pin2pad(_pinCTS), &funcsel);
if (retval != AP3_OK)
{
return retval;
Expand Down
39 changes: 39 additions & 0 deletions keywords.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#######################################
# Syntax Coloring Map For Wire
#######################################

#######################################
# Datatypes (KEYWORD1)
#######################################

#######################################
# Methods and Functions (KEYWORD2)
#######################################

enableBurstMode KEYWORD2
disableBurstMode KEYWORD2
getCpuFreqMHz KEYWORD2

getInternalTemp KEYWORD2

analogWriteResolution KEYWORD2
analogWriteFrameWidth KEYWORD2
analogWriteFrequency KEYWORD2
servoWrite KEYWORD2

enableFastShift KEYWORD2
fastShiftOut KEYWORD2
fastShiftIn KEYWORD2

secs KEYWORD2
systicks KEYWORD2
sysoverflows KEYWORD2

#######################################
# Instances (KEYWORD2)
#######################################

#######################################
# Constants (LITERAL1)
#######################################

Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
Using the differential ADC
By: Nathan Seidle
SparkFun Electronics
Date: July 17th, 2020
License: This code is public domain. Based on deepsleep.c from Ambiq SDK v2.2.0.

There are two differential ADC ports on the Artemis. These are located
on pads 12/13 (DIFF0N/DIFF0P) and 14/15 (DIFF1P/DIFF10).

A differential ADC port measures -1.0V to 1.0V with
0 = -1.0V, 8192 = 0V, and 16383 = 1.0V when the ADC is in 14-bit mode.

Using a trimpot, attach DIFF- to GND and DIFF+ to the center pin of the trimpot.
Connect the outer pins of the trimpot to 3.3V and GND.
Twisting the trimpot you should see the voltage change from 0 to 1.0V.
Switching DIFF-/+ you should see -1.0V to 0V.

SparkFun labored with love to create this code. Feel like supporting open source hardware?
Buy a board from SparkFun! https://www.sparkfun.com/products/15376
*/

#define ANALOG_RESOLUTION 14 //Artemis has 14 bit ADC but can range from 8 to 14 bit

int maxADCValue = pow(2, ANALOG_RESOLUTION);

void setup()
{
Serial.begin(115200);
Serial.println("Differential analog conversion example");

pinMode(LED_BUILTIN, OUTPUT);

analogReadResolution(ANALOG_RESOLUTION); //Default is 10 bit. Increase to 14 bit.
}

void loop()
{
int myAnalog0 = analogRead(ADIFF0); //Pads 12/13. Pins 9/10 on RedBoard Artemis.
//int myAnalog0 = analogRead(ADIFF1); //Pads 14/15
float myVoltage0 = mapfloat(myAnalog0, 0, maxADCValue, -1.0, 1.0);
Serial.print("Diff0 voltage: ");
Serial.print(myVoltage0, 3);
Serial.println();

digitalWrite(LED_BUILTIN, HIGH);
delay(25);
digitalWrite(LED_BUILTIN, LOW);
delay(25);
}

float mapfloat(float x, float in_min, float in_max, float out_min, float out_max)
{
if (x > in_max)
x = in_max;

return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}
Loading