Skip to content

Add RDA's new target UNO_81C #6508

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

Closed
wants to merge 2 commits into from
Closed
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
87 changes: 87 additions & 0 deletions targets/TARGET_RDA/TARGET_UNO_91H/PeripheralNames.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/* mbed Microcontroller Library
* Copyright (c) 2006-2013 ARM Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef MBED_PERIPHERALNAMES_H
#define MBED_PERIPHERALNAMES_H

#include "cmsis.h"
#include "PinNames.h"

#ifdef __cplusplus
extern "C" {
#endif

typedef enum {
UART_0 = (int)RDA_UART0_BASE,
UART_1 = (int)RDA_UART1_BASE
} UARTName;

typedef enum {
// Make sure GPIO_BASE & 0x1F == 0, store GPIO index at this field when mapping pins
GPIO_0 = (int)RDA_GPIO_BASE
} GPIOName;

typedef enum {
I2C_0 = (int)RDA_I2C0_BASE
} I2CName;

typedef enum {
SPI_0 = (int)RDA_SPI0_BASE
} SPIName;

typedef enum {
I2S_0 = (int)RDA_I2S_BASE
} I2SName;

typedef enum {
WDT_0 = (int)RDA_WDT_BASE
} WDTName;

typedef enum {
PWM_0 = 0,
PWM_1,
PWM_2,
PWM_3,
PWM_4,
PWM_5,
PWM_6,
PWM_7
} PWMName;

typedef enum {
ADC0_0 = 0,
ADC0_1,
ADC0_2
} ADCName;

typedef enum {
GPADC0_0 = 0,
GPADC0_1
} GPADCName;

#define STDIO_UART_TX UART0_TX
#define STDIO_UART_RX UART0_RX
#define STDIO_UART UART_0

// Default peripherals
#define MBED_UART0 PA_0, PA_1
#define MBED_UART1 PB_1, PB_2
#define MBED_UARTUSB USBTX, USBRX

#ifdef __cplusplus
}
#endif

#endif
180 changes: 180 additions & 0 deletions targets/TARGET_RDA/TARGET_UNO_91H/PinNames.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
/* mbed Microcontroller Library
* Copyright (c) 2006-2013 ARM Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef MBED_PINNAMES_H
#define MBED_PINNAMES_H

#include "cmsis.h"

#ifdef __cplusplus
extern "C" {
#endif

typedef enum {
PIN_INPUT,
PIN_OUTPUT
} PinDirection;

#define PORT_SHIFT 8

typedef enum {
PA_0 = (0 << PORT_SHIFT | 0 ),
PA_1 = (0 << PORT_SHIFT | 1 ),
PA_2 = (0 << PORT_SHIFT | 2 ),
PA_3 = (0 << PORT_SHIFT | 3 ),
PA_4 = (0 << PORT_SHIFT | 4 ),
PA_5 = (0 << PORT_SHIFT | 5 ),
PA_6 = (0 << PORT_SHIFT | 6 ),
PA_7 = (0 << PORT_SHIFT | 7 ),
PA_8 = (0 << PORT_SHIFT | 8 ),
PA_9 = (0 << PORT_SHIFT | 9 ),
PB_0 = (1 << PORT_SHIFT | 0 ),
PB_1 = (1 << PORT_SHIFT | 1 ),
PB_2 = (1 << PORT_SHIFT | 2 ),
PB_3 = (1 << PORT_SHIFT | 3 ),
PB_4 = (1 << PORT_SHIFT | 4 ),
PB_5 = (1 << PORT_SHIFT | 5 ),
PB_6 = (1 << PORT_SHIFT | 6 ),
PB_7 = (1 << PORT_SHIFT | 7 ),
PB_8 = (1 << PORT_SHIFT | 8 ),
PB_9 = (1 << PORT_SHIFT | 9 ),
PC_0 = (4 << PORT_SHIFT | 0 ),
PC_1 = (4 << PORT_SHIFT | 1 ),
PC_2 = (4 << PORT_SHIFT | 2 ),
PC_3 = (4 << PORT_SHIFT | 3 ),
PC_4 = (4 << PORT_SHIFT | 4 ),
PC_5 = (4 << PORT_SHIFT | 5 ),
PC_6 = (4 << PORT_SHIFT | 6 ),
PC_7 = (4 << PORT_SHIFT | 7 ),
PC_8 = (4 << PORT_SHIFT | 8 ),
PC_9 = (4 << PORT_SHIFT | 9 ),
PD_0 = (5 << PORT_SHIFT | 0 ),
PD_1 = (5 << PORT_SHIFT | 1 ),
PD_2 = (5 << PORT_SHIFT | 2 ),
PD_3 = (5 << PORT_SHIFT | 3 ),
PD_9 = (5 << PORT_SHIFT | 9 ), // Fake pin for GPADC_VBAT

UART0_RX = PA_0,
UART0_TX = PA_1,
UART1_RX = PB_1,
UART1_TX = PB_2,

USBRX = UART0_RX,
USBTX = UART0_TX,

I2C_SCL = PC_0,
I2C_SDA = PC_1,

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no SPI peripheral brought out?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 SPI master supported, Arduino like pin layout provided on the board (D10~D13).

Copy link
Contributor

@ashok-rao ashok-rao Apr 4, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In that case, you may want to define the Arduino pin maps also here (which I see is already done)..thanks!

I2S_TX_SD = PB_1,
I2S_TX_WS = PB_2,
I2S_TX_BCLK = PB_3,
I2S_RX_SD = PB_4,
I2S_RX_WS = PB_5,
I2S_RX_BCLK = PB_8,

GPIO_PIN0 = PB_0,
GPIO_PIN1 = PB_1,
GPIO_PIN2 = PB_2,
GPIO_PIN3 = PB_3,
GPIO_PIN4 = PB_4,
GPIO_PIN5 = PB_5,
GPIO_PIN6 = PB_6,
GPIO_PIN7 = PB_7,
GPIO_PIN8 = PB_8,
GPIO_PIN9 = PB_9,
GPIO_PIN10 = PA_8,
GPIO_PIN11 = PA_9,
GPIO_PIN12 = PC_0,
GPIO_PIN13 = PC_1,
GPIO_PIN14 = PC_2,
GPIO_PIN15 = PC_3,
GPIO_PIN16 = PC_4,
GPIO_PIN17 = PC_5,
GPIO_PIN18 = PC_6,
GPIO_PIN19 = PC_7,
GPIO_PIN20 = PC_8,
GPIO_PIN21 = PC_9,
GPIO_PIN22 = PD_0,
GPIO_PIN23 = PD_1,
GPIO_PIN24 = PD_2,
GPIO_PIN25 = PD_3,
GPIO_PIN26 = PA_0,
GPIO_PIN27 = PA_1,

// Another pin names for GPIO 14 - 19
GPIO_PIN14A = PA_2,
GPIO_PIN15A = PA_3,
GPIO_PIN16A = PA_4,
GPIO_PIN17A = PA_5,
GPIO_PIN18A = PA_6,
GPIO_PIN19A = PA_7,

ADC_PIN0 = PB_6,
ADC_PIN1 = PB_7,
ADC_PIN1A = PB_8, // Another pin name for ADC 1
ADC_PIN2 = PD_9,

LED1 = GPIO_PIN21,
LED2 = GPIO_PIN1,

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no user buttons or other analog input on the target?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The board contains 6 buttons, using only 1 ADC pin.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be useful to have atleast 1 button defined for user.

// Arduino Pin Names
// Analog Ports (A0-A1)
A0 = PB_6,
A1 = PB_8,
// A2
// A3
// Digital Pins with "An" name
A4 = PB_2,
A5 = PB_3,
// Digital Port (D0-D7)
D0 = PB_1,
D1 = PB_2,
D2 = PB_3,
D3 = PB_4,
D4 = PB_5,
D5 = PB_7,
D6 = PB_9,
D7 = PC_9,
// Digital Port (D8-D13)
D8 = PB_0,
// D9
D10 = PD_1, // CS0
D11 = PD_2, // MOSI
D12 = PD_3, // MISO
D13 = PD_0, // CLK
// GND
// AREF
SDA = PC_1,
D14 = SDA,
SCL = PC_0,
D15 = SCL,

// Not connected
NC = (int)0xFFFFFFFF
} PinName;

typedef enum {
PullNone = 0,
PullDown = 1,
PullUp = 2,
Repeater = 3,
PullDefault = Repeater,
} PinMode;

#ifdef __cplusplus
}
#endif

#endif
33 changes: 33 additions & 0 deletions targets/TARGET_RDA/TARGET_UNO_91H/PortNames.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/* mbed Microcontroller Library
* Copyright (c) 2006-2013 ARM Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef MBED_PORTNAMES_H
#define MBED_PORTNAMES_H

#ifdef __cplusplus
extern "C" {
#endif

typedef enum {
PortA = 0,
PortB = 1,
PortC = 4,
PortD = 5
} PortName;

#ifdef __cplusplus
}
#endif
#endif
92 changes: 92 additions & 0 deletions targets/TARGET_RDA/TARGET_UNO_91H/analogin_api.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/* mbed Microcontroller Library
* Copyright (c) 2006-2013 ARM Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "mbed_assert.h"
#include "analogin_api.h"
#include "pinmap.h"

#include "rda_ccfg_api.h"

#define ANALOGIN_MEDIAN_FILTER 1
#define RDA_ADC_RANGE (0x03FFU)

#if DEVICE_ANALOGIN
static const PinMap PinMap_ADC[] = {
{PB_6, ADC0_0, 0},
{PB_7, ADC0_1, 0},
{PB_8, ADC0_1, 0},
{PD_9, ADC0_2, 0},
{NC, NC, 0}
};
static unsigned char adc1_gp = 0U;
static int adc_inited_cnt = 0;

void analogin_init(analogin_t *obj, PinName pin)
{
unsigned char gp = (unsigned char)(pin & 0x00FFU);
obj->adc = (ADCName)pinmap_peripheral(pin, PinMap_ADC);
MBED_ASSERT(obj->adc != (ADCName)NC);

/* Init ADC */
if (0 == adc_inited_cnt) {
rda_ccfg_adc_init();
}
adc_inited_cnt++;
if (ADC0_2 == obj->adc) {
return;
}
if ((ADC0_1 == obj->adc) && (0U == adc1_gp)) {
adc1_gp = (2 >= rda_ccfg_hwver()) ? 7U : 8U;
MBED_ASSERT(gp == adc1_gp);
}
rda_ccfg_gp(gp, 0x00U);
rda_ccfg_adc_gp(gp, 0x00U);
rda_ccfg_adc_oenb(obj->adc, 0x01U);

pinmap_pinout(pin, PinMap_ADC);
}

uint16_t analogin_read_u16(analogin_t *obj)
{
uint16_t value = rda_ccfg_adc_read((unsigned char)(obj->adc));
return (value); // 10 bit
}

float analogin_read(analogin_t *obj)
{
uint16_t value = rda_ccfg_adc_read((unsigned char)(obj->adc));
return (float)value * (1.0f / (float)RDA_ADC_RANGE);
}

void analogin_free(analogin_t *obj)
{
unsigned char gp = 6U;
adc_inited_cnt--;
if (0 == adc_inited_cnt) {
rda_ccfg_adc_free();
}
if (ADC0_2 == obj->adc) {
return;
}
if (ADC0_1 == obj->adc) {
if (0U == adc1_gp) {
return;
}
gp = adc1_gp;
}
rda_ccfg_adc_gp(gp, 0x01U);
rda_ccfg_gp(gp, 0x01U);
}
#endif /* DEVICE_ANALOGIN */
Loading