Skip to content

Add Support for Toshiba TMPM3H6 #7536

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 2 commits into from Jul 20, 2018
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
108 changes: 108 additions & 0 deletions targets/TARGET_TOSHIBA/TARGET_TMPM3H6/PeripheralNames.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
/* mbed Microcontroller Library
* (C)Copyright TOSHIBA ELECTRONIC DEVICES & STORAGE CORPORATION 2018 All rights reserved
*
* 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 "PinNames.h"

#ifdef __cplusplus
extern "C" {
#endif

typedef enum {
SERIAL_0 = 0,
SERIAL_1,
SERIAL_2,
INVALID_SERIAL = (int)NC
} UARTName;

typedef enum {
ADC_AINA0 = 0,
ADC_AINA1,
ADC_AINA2,
ADC_AINA3,
ADC_AINA4,
ADC_AINA5,
ADC_AINA6,
ADC_AINA7,
ADC_AINA8,
ADC_AINA9,
ADC_AINA10,
ADC_AINA11,
ADC_AINA12,
ADC_AINA13,
ADC_AINA14,
ADC_AINA15,
INVALID_ADC = (int)NC
} ADCName;

typedef enum {
DAC_A0 = 0,
DAC_A1,
INVALID_DAC = (int)NC
} DACName;

typedef enum {
SPI_0 = 0,
SPI_1,
INVALID_SPI = (int)NC
} SPIName;

typedef enum {
I2C_0 = 0,
I2C_1,
I2C_2,
INVALID_I2C = (int)NC
} I2CName;

typedef enum {
PWM_0 = 0,
PWM_1,
PWM_2,
PWM_3,
PWM_4,
INVALID_PWM = (int)NC
} PWMName;

typedef enum {
GPIO_IRQ_0 = 0,
GPIO_IRQ_1,
GPIO_IRQ_2,
GPIO_IRQ_3,
GPIO_IRQ_4,
GPIO_IRQ_5,
GPIO_IRQ_6,
GPIO_IRQ_7,
GPIO_IRQ_8,
GPIO_IRQ_9,
GPIO_IRQ_A,
GPIO_IRQ_B,
GPIO_IRQ_C,
GPIO_IRQ_D,
GPIO_IRQ_E,
GPIO_IRQ_F,
INVALID_GPIO_IRQ = (int)NC
} GPIO_IRQName;

#define STDIO_UART_TX USBTX
#define STDIO_UART_RX USBRX
#define STDIO_UART SERIAL_1

#ifdef __cplusplus
}
#endif

#endif
121 changes: 121 additions & 0 deletions targets/TARGET_TOSHIBA/TARGET_TMPM3H6/PinNames.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
/* mbed Microcontroller Library
* (C)Copyright TOSHIBA ELECTRONIC DEVICES & STORAGE CORPORATION 2018 All rights reserved
*
* 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,
PIN_INOUT
} PinDirection;

typedef enum {
// TMPM3H6 Pin Names
PA0 = 0 << 3, PA1, PA2, PA3, PA4, PA5, PA6, PA7,
PB0 = 1 << 3, PB1, PB2, PB3, PB4, PB5, PB6, PB7,
PC0 = 2 << 3, PC1, PC2, PC3, PC4, PC5, PC6,
PD0 = 3 << 3, PD1, PD2, PD3,
PE0 = 4 << 3, PE1, PE2, PE3, PE4, PE5, PE6,
PF0 = 5 << 3, PF1, PF2, PF3, PF4,
PG0 = 6 << 3, PG1,
PH0 = 7 << 3, PH1, PH2, PH3,
PJ0 = 8 << 3, PJ1, PJ2, PJ3, PJ4, PJ5,
PK0 = 9 << 3, PK1, PK2, PK3, PK4, PK5, PK6, PK7,
PL0 = 10 << 3, PL1, PL2, PL3, PL4, PL5, PL6,
PM0 = 11 << 3, PM1, PM2, PM3, PM4, PM5, PM6,
PN0 = 12 << 3, PN1, PN2, PN3, PN4,PN5,
PP0 = 13 << 3, PP1, PP2, PP3,
PR0 = 14 << 3, PR1, PR2, PR3,

// Other mbed Pin Names
LED1 = PB4,
LED2 = PB5,
LED3 = PB6,
LED4 = PB7,

// external data bus Pin Names
D0 = PL0,
D1 = PL1,
D2 = PJ4,
D3 = PJ3,
D4 = PC4,
D5 = PC3,
D6 = PB3,
D7 = PB2,
D8 = PK1,
D9 = PJ0,
D10 = PL6,
D11 = PP1,
D12 = PP2,
D13 = PP0,
D14 = PA5,
D15 = PA4,

A0 = PE0,
A1 = PE1,
A2 = PE2,
A3 = PE3,
A4 = PE4,
A5 = PE5,

DAC0 = PG0,
DAC1 = PG1,

USBTX = PJ2,
USBRX = PJ1,

SW1 = PN4,
SW2 = PN3,
SW3 = PN2,
SW4 = PN1,

// I2C
EEPROM_SDA = PC1,
EEPROM_SCL = PC0,

// TSPI
MOSI = PP1,
MISO = PP2,
SCLK = PP0,

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

typedef enum {
PullUp = 0,
PullDown,
PullNone,
OpenDrain,
PullDefault
} PinMode;

typedef enum {
DISABLE = 0,
ENABLE
} FunctionalState;

#ifdef __cplusplus
}
#endif

#endif
47 changes: 47 additions & 0 deletions targets/TARGET_TOSHIBA/TARGET_TMPM3H6/PortNames.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/* mbed Microcontroller Library
* (C)Copyright TOSHIBA ELECTRONIC DEVICES & STORAGE CORPORATION 2018 All rights reserved
*
* 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,
PortC,
PortD,
PortE,
PortF,
PortG,
PortH,
PortJ,
PortK,
PortL,
PortM,
PortN,
PortP,
PortR,
} PortName;

#define IS_GPIO_PORT(param) ((param) <= PortR) // parameter checking for port number

#ifdef __cplusplus
}
#endif

#endif
91 changes: 91 additions & 0 deletions targets/TARGET_TOSHIBA/TARGET_TMPM3H6/analogin_api.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/* mbed Microcontroller Library
* (C)Copyright TOSHIBA ELECTRONIC DEVICES & STORAGE CORPORATION 2018 All rights reserved
*
* 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 "analogin_api.h"
#include "PeripheralNames.h"
#include "pinmap.h"
#include "mbed_wait_api.h"
#include "gpio_include.h"

static const PinMap PinMap_ADC[] = {
{PD0, ADC_AINA0, PIN_DATA(0, 0)},
{PD1, ADC_AINA1, PIN_DATA(0, 0)},
{PD2, ADC_AINA2, PIN_DATA(0, 0)},
{PD3, ADC_AINA3, PIN_DATA(0, 0)},
{PE0, ADC_AINA4, PIN_DATA(0, 0)},
{PE1, ADC_AINA5, PIN_DATA(0, 0)},
{PE2, ADC_AINA6, PIN_DATA(0, 0)},
{PE3, ADC_AINA7, PIN_DATA(0, 0)},
{PE4, ADC_AINA8, PIN_DATA(0, 0)},
{PE5, ADC_AINA9, PIN_DATA(0, 0)},
{PE6, ADC_AINA10, PIN_DATA(0, 0)},
{PF0, ADC_AINA11, PIN_DATA(0, 0)},
{PF1, ADC_AINA12, PIN_DATA(0, 0)},
{PF2, ADC_AINA13, PIN_DATA(0, 0)},
{PF3, ADC_AINA14, PIN_DATA(0, 0)},
{PF4, ADC_AINA15, PIN_DATA(0, 0)},
{NC, NC, 0}
};

void analogin_init(analogin_t *obj, PinName pin)
{
// Check that pin belong to ADC module
obj->adc = (ADCName)pinmap_peripheral(pin, PinMap_ADC);
MBED_ASSERT(obj->adc != (ADCName)NC);

obj->obj = TSB_ADA;
TSB_CG_FSYSENB_IPENB00 = ENABLE; // ADC CG Fsys Enable
pinmap_pinout(pin, PinMap_ADC); // Set pin function as ADC
obj->obj->CLK = ADC_SCLK_1; // Set sample hold time and prescale clock
obj->obj->MOD0 = (ADxMOD0_RCUT_NORMAL | ADxMOD0_DACON_ON);
TSB_CG_SPCLKEN_ADCKEN = ENABLE; // ADC Clock Enable
}

uint16_t analogin_read_u16(analogin_t *obj)
{
uint16_t ADCResultValue = 0;
uint32_t ADCResultStored = 0;

wait_us(3U); // Wait at least 3us to ensure the voltage is stable
obj->obj->CR0 = (ADxCR0_ADEN_DISABLE | ADxCR0_CNT_DISABLE); // Disable Conversion
obj->obj->TSET0 = (ADxTSETn_ENINT_DISABLE | ADxTSETn_TRGS_SGL | obj->adc); // Enable Conversion
obj->obj->CR1 = (ADxCR1_CNTDMEN_DISABLE | ADxCR1_SGLDMEN_DISABLE |
ADxCR1_TRGDMEN_DISABLE | ADxCR1_TRGEN_DISABLE);
obj->obj->CR0 = (ADxCR0_ADEN_ENABLE | ADxCR0_SGL_ENABLE | ADxCR0_CNT_DISABLE);

while ((obj->obj->ST & ADxST_SNGF_RUN) != ADxST_SNGF_IDLE) {
// Wait until AD conversion complete
}

wait_us(1U); // Wait for register to update with convert value.
ADCResultStored = obj->obj->REG0; // Convert result

if ((ADCResultStored & ADxREGn_ADRFn_MASK) == ADxREGn_ADRFn_ON) {
ADCResultValue = (uint16_t)((ADCResultStored & ADxREGn_ADRn_MASK) >> 4);
}

return ADCResultValue;
}

float analogin_read(analogin_t *obj)
{
float result = 0.0;
uint16_t value = 0;

value = analogin_read_u16(obj);
result = ((float)value * (1.0f / (float)ADC_12BIT_RANGE));

return result;
}
Loading