board.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2013 Ludwig Knüpfer <ludwig.knuepfer@fu-berlin.de>
3  *
4  * This file is subject to the terms and conditions of the GNU Lesser
5  * General Public License v2.1. See the file LICENSE in the top level
6  * directory for more details.
7  */
8 
22 #ifndef BOARD_H
23 #define BOARD_H
24 
25 #include <stdint.h>
26 
27 /* RIOT includes */
28 #include <motor_driver.h>
29 
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33 
34 #ifdef MODULE_MTD
35 #include "mtd_native.h"
36 #endif
37 
42 void _native_LED_GREEN_OFF(void);
43 void _native_LED_GREEN_ON(void);
44 void _native_LED_GREEN_TOGGLE(void);
45 void _native_LED_RED_OFF(void);
46 void _native_LED_RED_ON(void);
47 void _native_LED_RED_TOGGLE(void);
48 
49 #define LED0_ON (_native_LED_RED_ON())
50 #define LED0_OFF (_native_LED_RED_OFF())
51 #define LED0_TOGGLE (_native_LED_RED_TOGGLE())
52 #define LED1_ON (_native_LED_GREEN_ON())
53 #define LED1_OFF (_native_LED_GREEN_OFF())
54 #define LED1_TOGGLE (_native_LED_GREEN_TOGGLE())
55 
57 #if defined(MODULE_MTD) || DOXYGEN
58 
62 #ifndef MTD_PAGE_SIZE
63 #define MTD_PAGE_SIZE (256)
64 #endif
65 #ifndef MTD_SECTOR_SIZE
66 #define MTD_SECTOR_SIZE (4096)
67 #endif
68 #ifndef MTD_SECTOR_NUM
69 #define MTD_SECTOR_NUM (2048)
70 #endif
71 #ifndef MTD_NATIVE_FILENAME
72 #define MTD_NATIVE_FILENAME "MEMORY.bin"
73 #endif
74 
77 #define MTD_0 mtd0
78 
80 extern mtd_dev_t *mtd0;
81 #endif
82 
83 #if defined(MODULE_SPIFFS) || DOXYGEN
84 
88 /* SPIFFS config flags */
89 #ifndef SPIFFS_READ_ONLY
90 #define SPIFFS_READ_ONLY (0)
91 #endif
92 #ifndef SPIFFS_SINGLETON
93 #define SPIFFS_SINGLETON (0)
94 #endif
95 #ifndef SPIFFS_HAL_CALLBACK_EXTRA
96 #define SPIFFS_HAL_CALLBACK_EXTRA (1)
97 #endif
98 #ifndef SPIFFS_CACHE
99 #define SPIFFS_CACHE (1)
100 #endif
101 
102 #if SPIFFS_SINGLETON == 1
103 /* MTD config if singleton is used */
104 #ifndef SPIFFS_CFG_PHYS_SZ
105 #define SPIFFS_CFG_PHYS_SZ(ignore) (MTD_SECTOR_SIZE * MTD_SECTOR_NUM)
106 #endif
107 #ifndef SPIFFS_CFG_PHYS_ERASE_SZ
108 #define SPIFFS_CFG_PHYS_ERASE_SZ(ignore) (MTD_SECTOR_SIZE)
109 #endif
110 #ifndef SPIFFS_CFG_PHYS_ADDR
111 #define SPIFFS_CFG_PHYS_ADDR(ignore) (0)
112 #endif
113 #ifndef SPIFFS_CFG_LOG_PAGE_SZ
114 #define SPIFFS_CFG_LOG_PAGE_SZ(ignore) (MTD_PAGE_SIZE)
115 #endif
116 #ifndef SPIFFS_CFG_LOG_BLOCK_SZ
117 #define SPIFFS_CFG_LOG_BLOCK_SZ(ignore) (MTD_SECTOR_SIZE)
118 #endif
119 #endif
120 
121 #if SPIFFS_HAL_CALLBACK_EXTRA == 0
122 /* Default MTD device if no callback parameter */
123 #ifndef SPIFFS_MTD_DEV
124 #define SPIFFS_MTD_DEV (MTD_0)
125 #endif
126 #endif
127 
128 #endif
129 
140  const motor_driver_t motor_driver, uint8_t motor_id, \
141  int32_t pwm_duty_cycle);
142 
143 /* C++ standard do not support designated initializers */
144 #if !(defined __cplusplus) && (defined MODULE_PERIPH_QDEC)
145 
150 static const motor_driver_config_t motor_driver_config[] = {
151  {
152  .pwm_dev = 0,
153  .mode = MOTOR_DRIVER_1_DIR_BRAKE,
154  .mode_brake = MOTOR_BRAKE_LOW,
155  .pwm_mode = PWM_LEFT,
156  .pwm_frequency = 20000U,
157  .pwm_resolution = 1000U,
158  .nb_motors = 2,
159  .motors = {
160  {
161  .pwm_channel = 0,
162  .gpio_enable = GPIO_PIN(0, 0),
163  .gpio_dir0 = GPIO_PIN(0, 0),
164  .gpio_dir1_or_brake = GPIO_PIN(0, 0),
165  .gpio_dir_reverse = 0,
166  .gpio_enable_invert = 0,
167  .gpio_brake_invert = 0,
168  },
169  {
170  .pwm_channel = 1,
171  .gpio_enable = GPIO_PIN(0, 0),
172  .gpio_dir0 = GPIO_PIN(0, 0),
173  .gpio_dir1_or_brake = GPIO_PIN(0, 0),
174  .gpio_dir_reverse = 1,
175  .gpio_enable_invert = 0,
176  .gpio_brake_invert = 0,
177  },
178  },
180  },
181 };
182 
183 #define MOTOR_DRIVER_NUMOF ARRAY_SIZE(motor_driver_config)
184 
190 #define CONFIG_ZTIMER_USEC_TYPE ZTIMER_TYPE_PERIPH_TIMER
191 #define CONFIG_ZTIMER_USEC_DEV TIMER_DEV(0)
192 /* on native, anything can happen... */
193 #define CONFIG_ZTIMER_USEC_MIN (64)
194 
196 #endif /* __cplusplus */
197 
198 #ifdef __cplusplus
199 }
200 #endif
201 
203 #endif /* BOARD_H */
motor_driver.h
High-level driver for DC motors.
mtd_dev_t
MTD device descriptor.
Definition: mtd.h:58
motor_driver_config_t::pwm_dev
pwm_t pwm_dev
PWM device driving motors.
Definition: motor_driver.h:169
native_motor_driver_qdec_simulation
void native_motor_driver_qdec_simulation(const motor_driver_t motor_driver, uint8_t motor_id, int32_t pwm_duty_cycle)
Simulate QDEC on motor_set() calls.
mtd_native.h
MOTOR_BRAKE_LOW
@ MOTOR_BRAKE_LOW
Low stage brake.
Definition: motor_driver.h:128
motor_driver_t
unsigned int motor_driver_t
Default motor driver type definition.
Definition: motor_driver.h:156
PWM_LEFT
@ PWM_LEFT
left aligned PWM
Definition: periph_cpu.h:160
motor_driver_config_t
Describe DC motor driver with PWM device and motors array.
Definition: motor_driver.h:168
mtd0
mtd_dev_t * mtd0
mtd flash emulation device
MOTOR_DRIVER_1_DIR_BRAKE
@ MOTOR_DRIVER_1_DIR_BRAKE
Single GPIO for direction, \ Single GPIO for BRAKE.
Definition: motor_driver.h:120
GPIO_PIN
#define GPIO_PIN(x, y)
Define a CPU specific GPIO pin generator macro.
Definition: periph_cpu.h:35