Skip to content

Commit 057138c

Browse files
author
Cruz Monrreal
authored
Merge pull request #7536 from ganesh-ramachandran/master
Add Support for Toshiba TMPM3H6
2 parents 4bcca89 + 8673286 commit 057138c

36 files changed

+12604
-0
lines changed
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
/* mbed Microcontroller Library
2+
* (C)Copyright TOSHIBA ELECTRONIC DEVICES & STORAGE CORPORATION 2018 All rights reserved
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
#ifndef MBED_PERIPHERALNAMES_H
17+
#define MBED_PERIPHERALNAMES_H
18+
19+
#include "PinNames.h"
20+
21+
#ifdef __cplusplus
22+
extern "C" {
23+
#endif
24+
25+
typedef enum {
26+
SERIAL_0 = 0,
27+
SERIAL_1,
28+
SERIAL_2,
29+
INVALID_SERIAL = (int)NC
30+
} UARTName;
31+
32+
typedef enum {
33+
ADC_AINA0 = 0,
34+
ADC_AINA1,
35+
ADC_AINA2,
36+
ADC_AINA3,
37+
ADC_AINA4,
38+
ADC_AINA5,
39+
ADC_AINA6,
40+
ADC_AINA7,
41+
ADC_AINA8,
42+
ADC_AINA9,
43+
ADC_AINA10,
44+
ADC_AINA11,
45+
ADC_AINA12,
46+
ADC_AINA13,
47+
ADC_AINA14,
48+
ADC_AINA15,
49+
INVALID_ADC = (int)NC
50+
} ADCName;
51+
52+
typedef enum {
53+
DAC_A0 = 0,
54+
DAC_A1,
55+
INVALID_DAC = (int)NC
56+
} DACName;
57+
58+
typedef enum {
59+
SPI_0 = 0,
60+
SPI_1,
61+
INVALID_SPI = (int)NC
62+
} SPIName;
63+
64+
typedef enum {
65+
I2C_0 = 0,
66+
I2C_1,
67+
I2C_2,
68+
INVALID_I2C = (int)NC
69+
} I2CName;
70+
71+
typedef enum {
72+
PWM_0 = 0,
73+
PWM_1,
74+
PWM_2,
75+
PWM_3,
76+
PWM_4,
77+
INVALID_PWM = (int)NC
78+
} PWMName;
79+
80+
typedef enum {
81+
GPIO_IRQ_0 = 0,
82+
GPIO_IRQ_1,
83+
GPIO_IRQ_2,
84+
GPIO_IRQ_3,
85+
GPIO_IRQ_4,
86+
GPIO_IRQ_5,
87+
GPIO_IRQ_6,
88+
GPIO_IRQ_7,
89+
GPIO_IRQ_8,
90+
GPIO_IRQ_9,
91+
GPIO_IRQ_A,
92+
GPIO_IRQ_B,
93+
GPIO_IRQ_C,
94+
GPIO_IRQ_D,
95+
GPIO_IRQ_E,
96+
GPIO_IRQ_F,
97+
INVALID_GPIO_IRQ = (int)NC
98+
} GPIO_IRQName;
99+
100+
#define STDIO_UART_TX USBTX
101+
#define STDIO_UART_RX USBRX
102+
#define STDIO_UART SERIAL_1
103+
104+
#ifdef __cplusplus
105+
}
106+
#endif
107+
108+
#endif
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
/* mbed Microcontroller Library
2+
* (C)Copyright TOSHIBA ELECTRONIC DEVICES & STORAGE CORPORATION 2018 All rights reserved
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
#ifndef MBED_PINNAMES_H
17+
#define MBED_PINNAMES_H
18+
19+
#include "cmsis.h"
20+
21+
#ifdef __cplusplus
22+
extern "C" {
23+
#endif
24+
25+
typedef enum {
26+
PIN_INPUT,
27+
PIN_OUTPUT,
28+
PIN_INOUT
29+
} PinDirection;
30+
31+
typedef enum {
32+
// TMPM3H6 Pin Names
33+
PA0 = 0 << 3, PA1, PA2, PA3, PA4, PA5, PA6, PA7,
34+
PB0 = 1 << 3, PB1, PB2, PB3, PB4, PB5, PB6, PB7,
35+
PC0 = 2 << 3, PC1, PC2, PC3, PC4, PC5, PC6,
36+
PD0 = 3 << 3, PD1, PD2, PD3,
37+
PE0 = 4 << 3, PE1, PE2, PE3, PE4, PE5, PE6,
38+
PF0 = 5 << 3, PF1, PF2, PF3, PF4,
39+
PG0 = 6 << 3, PG1,
40+
PH0 = 7 << 3, PH1, PH2, PH3,
41+
PJ0 = 8 << 3, PJ1, PJ2, PJ3, PJ4, PJ5,
42+
PK0 = 9 << 3, PK1, PK2, PK3, PK4, PK5, PK6, PK7,
43+
PL0 = 10 << 3, PL1, PL2, PL3, PL4, PL5, PL6,
44+
PM0 = 11 << 3, PM1, PM2, PM3, PM4, PM5, PM6,
45+
PN0 = 12 << 3, PN1, PN2, PN3, PN4,PN5,
46+
PP0 = 13 << 3, PP1, PP2, PP3,
47+
PR0 = 14 << 3, PR1, PR2, PR3,
48+
49+
// Other mbed Pin Names
50+
LED1 = PB4,
51+
LED2 = PB5,
52+
LED3 = PB6,
53+
LED4 = PB7,
54+
55+
// external data bus Pin Names
56+
D0 = PL0,
57+
D1 = PL1,
58+
D2 = PJ4,
59+
D3 = PJ3,
60+
D4 = PC4,
61+
D5 = PC3,
62+
D6 = PB3,
63+
D7 = PB2,
64+
D8 = PK1,
65+
D9 = PJ0,
66+
D10 = PL6,
67+
D11 = PP1,
68+
D12 = PP2,
69+
D13 = PP0,
70+
D14 = PA5,
71+
D15 = PA4,
72+
73+
A0 = PE0,
74+
A1 = PE1,
75+
A2 = PE2,
76+
A3 = PE3,
77+
A4 = PE4,
78+
A5 = PE5,
79+
80+
DAC0 = PG0,
81+
DAC1 = PG1,
82+
83+
USBTX = PJ2,
84+
USBRX = PJ1,
85+
86+
SW1 = PN4,
87+
SW2 = PN3,
88+
SW3 = PN2,
89+
SW4 = PN1,
90+
91+
// I2C
92+
EEPROM_SDA = PC1,
93+
EEPROM_SCL = PC0,
94+
95+
// TSPI
96+
MOSI = PP1,
97+
MISO = PP2,
98+
SCLK = PP0,
99+
100+
// Not connected
101+
NC = (int)0xFFFFFFFF,
102+
} PinName;
103+
104+
typedef enum {
105+
PullUp = 0,
106+
PullDown,
107+
PullNone,
108+
OpenDrain,
109+
PullDefault
110+
} PinMode;
111+
112+
typedef enum {
113+
DISABLE = 0,
114+
ENABLE
115+
} FunctionalState;
116+
117+
#ifdef __cplusplus
118+
}
119+
#endif
120+
121+
#endif
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/* mbed Microcontroller Library
2+
* (C)Copyright TOSHIBA ELECTRONIC DEVICES & STORAGE CORPORATION 2018 All rights reserved
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
#ifndef MBED_PORTNAMES_H
17+
#define MBED_PORTNAMES_H
18+
19+
#ifdef __cplusplus
20+
extern "C" {
21+
#endif
22+
23+
typedef enum {
24+
PortA = 0,
25+
PortB,
26+
PortC,
27+
PortD,
28+
PortE,
29+
PortF,
30+
PortG,
31+
PortH,
32+
PortJ,
33+
PortK,
34+
PortL,
35+
PortM,
36+
PortN,
37+
PortP,
38+
PortR,
39+
} PortName;
40+
41+
#define IS_GPIO_PORT(param) ((param) <= PortR) // parameter checking for port number
42+
43+
#ifdef __cplusplus
44+
}
45+
#endif
46+
47+
#endif
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
/* mbed Microcontroller Library
2+
* (C)Copyright TOSHIBA ELECTRONIC DEVICES & STORAGE CORPORATION 2018 All rights reserved
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
#include "analogin_api.h"
17+
#include "PeripheralNames.h"
18+
#include "pinmap.h"
19+
#include "mbed_wait_api.h"
20+
#include "gpio_include.h"
21+
22+
static const PinMap PinMap_ADC[] = {
23+
{PD0, ADC_AINA0, PIN_DATA(0, 0)},
24+
{PD1, ADC_AINA1, PIN_DATA(0, 0)},
25+
{PD2, ADC_AINA2, PIN_DATA(0, 0)},
26+
{PD3, ADC_AINA3, PIN_DATA(0, 0)},
27+
{PE0, ADC_AINA4, PIN_DATA(0, 0)},
28+
{PE1, ADC_AINA5, PIN_DATA(0, 0)},
29+
{PE2, ADC_AINA6, PIN_DATA(0, 0)},
30+
{PE3, ADC_AINA7, PIN_DATA(0, 0)},
31+
{PE4, ADC_AINA8, PIN_DATA(0, 0)},
32+
{PE5, ADC_AINA9, PIN_DATA(0, 0)},
33+
{PE6, ADC_AINA10, PIN_DATA(0, 0)},
34+
{PF0, ADC_AINA11, PIN_DATA(0, 0)},
35+
{PF1, ADC_AINA12, PIN_DATA(0, 0)},
36+
{PF2, ADC_AINA13, PIN_DATA(0, 0)},
37+
{PF3, ADC_AINA14, PIN_DATA(0, 0)},
38+
{PF4, ADC_AINA15, PIN_DATA(0, 0)},
39+
{NC, NC, 0}
40+
};
41+
42+
void analogin_init(analogin_t *obj, PinName pin)
43+
{
44+
// Check that pin belong to ADC module
45+
obj->adc = (ADCName)pinmap_peripheral(pin, PinMap_ADC);
46+
MBED_ASSERT(obj->adc != (ADCName)NC);
47+
48+
obj->obj = TSB_ADA;
49+
TSB_CG_FSYSENB_IPENB00 = ENABLE; // ADC CG Fsys Enable
50+
pinmap_pinout(pin, PinMap_ADC); // Set pin function as ADC
51+
obj->obj->CLK = ADC_SCLK_1; // Set sample hold time and prescale clock
52+
obj->obj->MOD0 = (ADxMOD0_RCUT_NORMAL | ADxMOD0_DACON_ON);
53+
TSB_CG_SPCLKEN_ADCKEN = ENABLE; // ADC Clock Enable
54+
}
55+
56+
uint16_t analogin_read_u16(analogin_t *obj)
57+
{
58+
uint16_t ADCResultValue = 0;
59+
uint32_t ADCResultStored = 0;
60+
61+
wait_us(3U); // Wait at least 3us to ensure the voltage is stable
62+
obj->obj->CR0 = (ADxCR0_ADEN_DISABLE | ADxCR0_CNT_DISABLE); // Disable Conversion
63+
obj->obj->TSET0 = (ADxTSETn_ENINT_DISABLE | ADxTSETn_TRGS_SGL | obj->adc); // Enable Conversion
64+
obj->obj->CR1 = (ADxCR1_CNTDMEN_DISABLE | ADxCR1_SGLDMEN_DISABLE |
65+
ADxCR1_TRGDMEN_DISABLE | ADxCR1_TRGEN_DISABLE);
66+
obj->obj->CR0 = (ADxCR0_ADEN_ENABLE | ADxCR0_SGL_ENABLE | ADxCR0_CNT_DISABLE);
67+
68+
while ((obj->obj->ST & ADxST_SNGF_RUN) != ADxST_SNGF_IDLE) {
69+
// Wait until AD conversion complete
70+
}
71+
72+
wait_us(1U); // Wait for register to update with convert value.
73+
ADCResultStored = obj->obj->REG0; // Convert result
74+
75+
if ((ADCResultStored & ADxREGn_ADRFn_MASK) == ADxREGn_ADRFn_ON) {
76+
ADCResultValue = (uint16_t)((ADCResultStored & ADxREGn_ADRn_MASK) >> 4);
77+
}
78+
79+
return ADCResultValue;
80+
}
81+
82+
float analogin_read(analogin_t *obj)
83+
{
84+
float result = 0.0;
85+
uint16_t value = 0;
86+
87+
value = analogin_read_u16(obj);
88+
result = ((float)value * (1.0f / (float)ADC_12BIT_RANGE));
89+
90+
return result;
91+
}

0 commit comments

Comments
 (0)