Skip to content

Commit 6b7f804

Browse files
committed
Example app
1 parent cb04609 commit 6b7f804

File tree

1 file changed

+281
-0
lines changed

1 file changed

+281
-0
lines changed

main.cpp

Lines changed: 281 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,281 @@
1+
/* Copyright (c) 2018 Arm Limited
2+
*
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
#include "mbed.h"
18+
#include "explicit_pinmap.h"
19+
20+
#ifndef RUN_EXP
21+
#define RUN_EXP 1
22+
#endif
23+
24+
#if DEVICE_SPI
25+
static void test_spi()
26+
{
27+
#if !RUN_EXP
28+
/* Regular use (master) */
29+
SPI spi(D1, D2, D3, D4);
30+
#else
31+
/* Explicit pinmap */
32+
//constexpr spi_pinmap_t explicit_spi_pinmap = get_spi_pinmap(PTD2, PTD3, PTD1, PTD0); // K64F
33+
//constexpr spi_pinmap_t explicit_spi_pinmap = get_spi_pinmap(PA_7, PA_6, PA_5, PA_4); // NUCLEO_F429ZI
34+
//constexpr spi_pinmap_t explicit_spi_pinmap = get_spi_pinmap(PA_7, PA_6, PA_5, PA_4); // NUCLEO_F411RE
35+
//constexpr spi_pinmap_t explicit_spi_pinmap = get_spi_pinmap(P0_3, P0_2, P0_6, P0_4); // LPC
36+
//constexpr spi_pinmap_t explicit_spi_pinmap = get_spi_pinmap(PA_7, PA_6, PA_5, PA_4); // DISCO
37+
//constexpr spi_pinmap_t explicit_spi_pinmap = get_spi_pinmap(PA_7, PA_6, PA_5, PA_4); // NUCLEO_F303RE
38+
constexpr spi_pinmap_t explicit_spi_pinmap = get_spi_pinmap(PA_7, PA_6, PA_5, PA_4); // NUCLEO_L073RZ
39+
40+
SPI spi(explicit_spi_pinmap);
41+
#endif
42+
spi.format(8,0);
43+
}
44+
#endif
45+
46+
#if DEVICE_PWMOUT
47+
static void test_pwm()
48+
{
49+
#if !RUN_EXP
50+
PwmOut led(LED1);
51+
#else
52+
//constexpr PinMap explicit_pinmap = get_pwm_pinmap(PTA1); // K64F
53+
//constexpr PinMap explicit_pinmap = get_pwm_pinmap(PA_0); // NUCLEO_F429ZI
54+
//constexpr PinMap explicit_pinmap = get_pwm_pinmap(PA_0); // NUCLEO_F411RE
55+
//constexpr PinMap explicit_pinmap = get_pwm_pinmap(PA_0); // NUCLEO_F303RE
56+
constexpr PinMap explicit_pinmap = get_pwm_pinmap(PA_0); // NUCLEO_L073RZ
57+
58+
PwmOut led(explicit_pinmap);
59+
#endif
60+
led.period(4.0f); // 4 second period
61+
led.write(0.50f); // 50% duty cycle, relative to period
62+
}
63+
#endif
64+
65+
#if DEVICE_ANALOGIN
66+
static void test_analogin()
67+
{
68+
#if !RUN_EXP
69+
AnalogIn ain(ADC_VREF);
70+
#else
71+
//constexpr PinMap explicit_pinmap = get_analogin_pinmap(PTB2); // K64F
72+
//constexpr PinMap explicit_pinmap = get_analogin_pinmap(PA_0); // NUCLEO_F429ZI
73+
//constexpr PinMap explicit_pinmap = get_analogin_pinmap(PA_0); // NUCLEO_F411RE
74+
//constexpr PinMap explicit_pinmap = get_analogin_pinmap(p2); // NORDIC
75+
//constexpr PinMap explicit_pinmap = get_analogin_pinmap(PA_0); // DISCO
76+
//constexpr PinMap explicit_pinmap = get_analogin_pinmap(P0_23); // LPC
77+
constexpr PinMap explicit_pinmap = get_analogin_pinmap(PA_0); // NUCLEO_L073RZ
78+
79+
AnalogIn ain(explicit_pinmap);
80+
#endif
81+
if(ain > 0.3f) {
82+
while(1);
83+
}
84+
}
85+
#endif
86+
87+
#if DEVICE_ANALOGOUT
88+
static void test_analogout()
89+
{
90+
#if !RUN_EXP
91+
AnalogOut aout(D1);
92+
#else
93+
//constexpr PinMap explicit_pinmap = get_analogout_pinmap(DAC0_OUT); // K64F
94+
//constexpr PinMap explicit_pinmap = get_analogout_pinmap(PA_4); // NUCLEO_F429ZI
95+
//constexpr PinMap explicit_pinmap = get_analogout_pinmap(PA_4); // DISCO
96+
//constexpr PinMap explicit_pinmap = get_analogout_pinmap(PA_4); // NUCLEO_F303RE
97+
constexpr PinMap explicit_pinmap = get_analogout_pinmap(PA_4); // NUCLEO_L073RZ
98+
99+
AnalogOut aout(explicit_pinmap);
100+
#endif
101+
aout = 0.1;
102+
}
103+
#endif
104+
105+
#if DEVICE_I2C
106+
static void test_i2c()
107+
{
108+
#if !RUN_EXP
109+
I2C i2c(D1, D2);
110+
#else
111+
//constexpr i2c_pinmap_t explicit_pinmap = get_i2c_pinmap(PTB1, PTB0); // K64F
112+
//constexpr i2c_pinmap_t explicit_pinmap = get_i2c_pinmap(PB_7, PA_8); // NUCLEO_F429ZI
113+
//constexpr i2c_pinmap_t explicit_pinmap = get_i2c_pinmap(PB_3, PB_10); // NUCLEO_F411RE
114+
//constexpr i2c_pinmap_t explicit_pinmap = get_i2c_pinmap(PB_9, PB_8); // DISCO
115+
//constexpr i2c_pinmap_t explicit_pinmap = get_i2c_pinmap(PA_10, PA_9); // NUCLEO_F303RE
116+
//constexpr i2c_pinmap_t explicit_pinmap = get_i2c_pinmap(P0_13, P0_14); // LPC
117+
constexpr i2c_pinmap_t explicit_pinmap = get_i2c_pinmap(PA_10, PA_9); // NUCLEO_L073RZ
118+
119+
I2C i2c(explicit_pinmap);
120+
#endif
121+
i2c.frequency(1000000);
122+
}
123+
#endif
124+
125+
#if DEVICE_SERIAL
126+
static void test_serial()
127+
{
128+
#if !RUN_EXP
129+
Serial serial(D1, D2);
130+
serial.set_flow_control(Serial::RTSCTS, D1, D2);
131+
#else
132+
//constexpr serial_pinmap_t explicit_pinmap = get_uart_pinmap(PA_0, PA_1); // NUCLEO_F429ZI
133+
//constexpr serial_pinmap_t explicit_pinmap = get_uart_pinmap(P0_30, P0_29); // NORDIC
134+
//constexpr serial_pinmap_t explicit_pinmap = get_uart_pinmap(PA_0, PA_1); // DISCO
135+
//constexpr serial_pinmap_t explicit_pinmap = get_uart_pinmap(PA_2, PA_3); // NUCLEO_F411RE
136+
//constexpr serial_pinmap_t explicit_pinmap = get_uart_pinmap(PA_2, PA_3); // NUCLEO_F303RE
137+
//constexpr serial_pinmap_t explicit_pinmap = get_uart_pinmap(P0_30, P0_29); // LPC
138+
constexpr serial_pinmap_t explicit_pinmap = get_uart_pinmap(PA_0, PA_1); // NUCLEO_L073RZ
139+
140+
141+
//constexpr serial_fc_pinmap_t explicit_pinmap_fc = get_uart_fc_pinmap(PA_0, PA_1); // NUCLEO_F429ZI
142+
//constexpr serial_fc_pinmap_t explicit_pinmap_fc = get_uart_fc_pinmap(P1_8, P1_7); // NORDIC
143+
//constexpr serial_fc_pinmap_t explicit_pinmap_fc = get_uart_fc_pinmap(PA_0, PA_1); // DISCO
144+
//constexpr serial_fc_pinmap_t explicit_pinmap_fc = get_uart_fc_pinmap(PA_0, PA_1); // NUCLEO_F411RE
145+
//constexpr serial_fc_pinmap_t explicit_pinmap_fc = get_uart_fc_pinmap(PA_0, PA_1); // NUCLEO_F303RE
146+
//constexpr serial_fc_pinmap_t explicit_pinmap_fc = get_uart_fc_pinmap(P1_7, P1_8); // LPC
147+
constexpr serial_fc_pinmap_t explicit_pinmap_fc = get_uart_fc_pinmap(PA_0, PA_1); // NUCLEO_L073RZ
148+
149+
Serial serial(explicit_pinmap);
150+
151+
serial.set_flow_control(Serial::RTSCTS, explicit_pinmap_fc);
152+
#endif
153+
if (serial.readable()) {
154+
while(1);
155+
}
156+
}
157+
#endif
158+
159+
#if DEVICE_QSPI
160+
static void test_qspi()
161+
{
162+
#if !RUN_EXP
163+
QSPI qspi_device(PB_1, PB_0, PA_7, PA_6, PB_10, PB_11);
164+
#else
165+
constexpr qspi_pinmap_t explicit_pinmap = get_qspi_pinmap(PB_1, PB_0, PA_7, PA_6, PB_10, PB_11); // DISCO
166+
QSPI qspi_device(explicit_pinmap);
167+
qspi_device.configure_format(QSPI_CFG_BUS_SINGLE, QSPI_CFG_BUS_SINGLE,
168+
QSPI_CFG_ADDR_SIZE_24, QSPI_CFG_BUS_SINGLE,
169+
QSPI_CFG_ALT_SIZE_8, QSPI_CFG_BUS_SINGLE, 0);
170+
#endif
171+
172+
}
173+
#endif
174+
175+
#if DEVICE_CAN
176+
static void test_can()
177+
{
178+
char counter;
179+
180+
#if !RUN_EXP
181+
CAN can(PA_11, PA_12);
182+
#else
183+
184+
//constexpr can_pinmap_t explicit_pinmap = get_can_pinmap(PA_11, PA_12); // DISCO
185+
constexpr can_pinmap_t explicit_pinmap = get_can_pinmap(PA_11, PA_12); // NUCLEO_F429ZI
186+
CAN can(explicit_pinmap, 10000);
187+
#endif
188+
can.write(CANMessage(1337, &counter, 1));
189+
}
190+
#endif
191+
192+
static void test_sizes()
193+
{
194+
uint32_t PINMAP_ANALOGIN_SIZE = 0;
195+
uint32_t PINMAP_ANALOGOUT_SIZE = 0;
196+
uint32_t PINMAP_I2C_SIZE = 0;
197+
uint32_t PINMAP_UART_SIZE = 0;
198+
uint32_t PINMAP_SPI_SIZE = 0;
199+
uint32_t PINMAP_PWM_SIZE = 0;
200+
uint32_t PINMAP_QSPI_SIZE = 0;
201+
uint32_t PINMAP_CAN_SIZE = 0;
202+
203+
204+
#ifdef PINMAP_ANALOGIN
205+
PINMAP_ANALOGIN_SIZE = sizeof(PINMAP_ANALOGIN);
206+
#endif
207+
208+
#ifdef PINMAP_ANALOGIN_INTERNAL
209+
PINMAP_ANALOGIN_SIZE += sizeof(PINMAP_ANALOGIN_INTERNAL);
210+
#endif
211+
212+
#ifdef PINMAP_ANALOGOUT
213+
PINMAP_ANALOGOUT_SIZE = sizeof(PINMAP_ANALOGOUT);
214+
#endif
215+
216+
#ifdef PINMAP_I2C_SDA
217+
PINMAP_I2C_SIZE = sizeof(PINMAP_I2C_SDA) + sizeof(PINMAP_I2C_SCL);
218+
#endif
219+
220+
#ifdef PINMAP_UART_TX
221+
PINMAP_UART_SIZE = sizeof(PINMAP_UART_TX) + sizeof(PINMAP_UART_RX);
222+
#endif
223+
224+
#ifdef PINMAP_UART_CTS
225+
PINMAP_UART_SIZE += sizeof(PinMap_UART_CTS) + sizeof(PinMap_UART_RTS);
226+
#endif
227+
228+
#ifdef PINMAP_SPI_SCLK
229+
PINMAP_SPI_SIZE = sizeof(PINMAP_SPI_SCLK) + sizeof(PINMAP_SPI_MOSI) + sizeof(PINMAP_SPI_MISO) + sizeof(PINMAP_SPI_SSEL);
230+
#endif
231+
232+
#ifdef PINMAP_PWM
233+
PINMAP_PWM_SIZE = sizeof(PINMAP_PWM);
234+
#endif
235+
236+
#ifdef PINMAP_QSPI_DATA0
237+
PINMAP_QSPI_SIZE = sizeof(PINMAP_QSPI_DATA0) + sizeof(PINMAP_QSPI_DATA1) + sizeof(PINMAP_QSPI_DATA2) + sizeof(PINMAP_QSPI_DATA3) + sizeof(PinMap_QSPI_SCLK) + sizeof(PinMap_QSPI_SSEL);
238+
#endif
239+
240+
#ifdef PINMAP_CAN_RD
241+
PINMAP_CAN_SIZE = sizeof(PINMAP_CAN_RD) + sizeof(PINMAP_CAN_TD);
242+
#endif
243+
244+
printf("PINMAP_ANALOGIN_SIZE: %u \r\n", PINMAP_ANALOGIN_SIZE);
245+
printf("PINMAP_ANALOGOUT_SIZE: %u \r\n", PINMAP_ANALOGOUT_SIZE);
246+
printf("PINMAP_I2C_SIZE: %u \r\n", PINMAP_I2C_SIZE);
247+
printf("PINMAP_UART_SIZE: %u \r\n", PINMAP_UART_SIZE);
248+
printf("PINMAP_SPI_SIZE: %u \r\n", PINMAP_SPI_SIZE);
249+
printf("PINMAP_PWM_SIZE: %u \r\n", PINMAP_PWM_SIZE);
250+
printf("PINMAP_QSPI_SIZE: %u \r\n", PINMAP_QSPI_SIZE);
251+
printf("PINMAP_CAN_SIZE: %u \r\n", PINMAP_CAN_SIZE);
252+
253+
}
254+
255+
256+
257+
int main()
258+
{
259+
//test_pwm();
260+
261+
//test_analogin();
262+
263+
//test_analogout();
264+
265+
//test_spi();
266+
267+
//test_i2c();
268+
269+
//test_serial();
270+
271+
//test_qspi();
272+
273+
test_can();
274+
275+
//test_sizes();
276+
277+
while(1);
278+
279+
return 0;
280+
281+
}

0 commit comments

Comments
 (0)