Loading...
Searching...
No Matches
periph_conf_atmega_common.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2014 Freie Universität Berlin, Hinnerk van Bruinehsen
3 * 2016 Laurent Navet <laurent.navet@gmail.com>
4 * 2016 RWTH Aachen, Josua Arndt
5 * 2016 INRIA, Francisco Acosta
6 * 2017 HAW Hamburg, Dimitri Nahm
7 * 2018 Matthew Blue <matthew.blue.neuro@gmail.com>
8 * 2019 Otto-von-Guericke-Universität Magdeburg
9 * 2023 Hugues Larrive
10 *
11 * This file is subject to the terms and conditions of the GNU Lesser
12 * General Public License v2.1. See the file LICENSE in the top level
13 * directory for more details.
14 */
15
35#ifndef PERIPH_CONF_ATMEGA_COMMON_H
36#define PERIPH_CONF_ATMEGA_COMMON_H
37
38#include "periph_cpu.h"
39
40#ifdef __cplusplus
41extern "C" {
42#endif
43
48#ifndef CLOCK_CORECLOCK
49#define CLOCK_CORECLOCK (16000000UL)
50#endif /* CLOCK_CORECLOCK */
63#ifndef UART_NUMOF
64#if defined(CPU_ATMEGA128RFA1) || defined(CPU_ATMEGA256RFR2) || \
65 defined(CPU_ATMEGA1281) || defined(CPU_ATMEGA1284P) || defined(CPU_ATMEGA2560)
66 #define UART_NUMOF (2U)
67
68 /* UART0 is used for stdio */
69 #define UART_0 MEGA_UART0
70 #define UART_0_ISR USART0_RX_vect
71 #define UART_0_ISR_TX USART0_TX_vect
72
73 #define UART_1 MEGA_UART1
74 #define UART_1_ISR USART1_RX_vect
75 #define UART_1_ISR_TX USART1_TX_vect
76#elif defined(CPU_ATMEGA8)
77 #define UART_NUMOF (1U)
78
79 #define UART_0 MEGA_UART
80 #define UART_0_ISR USART_RXC_vect
81 #define UART_0_ISR_TX USART_TXC_vect
82#elif defined(CPU_ATMEGA328P)
83 #define UART_NUMOF (1U)
84
85 #define UART_0 MEGA_UART0
86 #define UART_0_ISR USART_RX_vect
87 #define UART_0_ISR_TX USART_TX_vect
88#elif defined(CPU_ATMEGA32U4)
89 #define UART_NUMOF (1U)
90
91 #define UART_0 MEGA_UART1
92 #define UART_0_ISR USART1_RX_vect
93 #define UART_0_ISR_TX USART1_TX_vect
94#else
95 #define UART_NUMOF (0U)
96#endif
97#endif /* UART_NUMOF */
140#ifndef SPI_NUMOF
141#define SPI_NUMOF (1U)
142#endif /* SPI_NUMOF */
149#ifndef I2C_NUMOF
150#define I2C_BUS_SPEED I2C_SPEED_FAST
151#define I2C_NUMOF (1U)
152#endif /* I2C_NUMOF */
165#ifndef ADC_NUMOF
166#if defined(CPU_ATMEGA128RFA1) || defined(CPU_ATMEGA256RFR2) || defined(CPU_ATMEGA328P) || \
167 defined(CPU_ATMEGA1281) || defined(CPU_ATMEGA1284P) || defined(CPU_ATMEGA32U4) || \
168 defined(CPU_ATMEGA8)
169 #define ADC_NUMOF (8U)
170#elif defined (CPU_ATMEGA2560)
171 #define ADC_NUMOF (16U)
172#else
173 #define ADC_NUMOF (0U)
174#endif
175#endif /* ADC_NUMOF */
191#ifndef PWM_NUMOF
192#if defined(CPU_ATMEGA8)
193 #define PWM_PINS_CH0 { GPIO_PIN(PORT_B, 3), GPIO_UNDEF }
194#elif defined(CPU_ATMEGA328P)
195 #define PWM_PINS_CH0 { GPIO_PIN(PORT_D, 6), GPIO_PIN(PORT_D, 5) }
196 #define PWM_PINS_CH1 { GPIO_PIN(PORT_B, 3), GPIO_PIN(PORT_D, 3) }
197#elif defined(CPU_ATMEGA1281)
198 #define PWM_PINS_CH0 { GPIO_PIN(PORT_B, 7), GPIO_PIN(PORT_G, 5) }
199 #define PWM_PINS_CH1 { GPIO_PIN(PORT_B, 4), GPIO_UNDEF }
200#elif defined(CPU_ATMEGA1284P)
201 #define PWM_PINS_CH0 { GPIO_PIN(PORT_B, 3), GPIO_PIN(PORT_B, 4) }
202 #define PWM_PINS_CH1 { GPIO_PIN(PORT_D, 7), GPIO_PIN(PORT_D, 6) }
203#elif defined(CPU_ATMEGA2560)
204 #define PWM_PINS_CH0 { GPIO_PIN(PORT_B, 7), GPIO_PIN(PORT_G, 5) }
205 #define PWM_PINS_CH1 { GPIO_PIN(PORT_B, 4), GPIO_PIN(PORT_H, 6) }
206#elif defined(CPU_ATMEGA32U4)
207 #define PWM_PINS_CH0 { GPIO_PIN(PORT_B, 7), GPIO_PIN(PORT_D, 0) }
208#else
209 #define PWM_NUMOF (0U)
210#endif
211
212#if defined(CPU_ATMEGA32U4) || defined(CPU_ATMEGA328P) || \
213 defined(CPU_ATMEGA1281) || defined(CPU_ATMEGA1284P) || \
214 defined(CPU_ATMEGA2560) || defined(CPU_ATMEGA8)
215 static const pwm_conf_t pwm_conf[] = {
216#ifndef CPU_ATMEGA8
217 {
218 .dev = MINI_TIMER0,
219 .pin_ch = PWM_PINS_CH0,
220 .div = MINI_TIMER0_DIV,
221 },
222#ifndef CPU_ATMEGA32U4
223 {
224 .dev = MINI_TIMER2,
225 .pin_ch = PWM_PINS_CH1,
226 .div = MINI_TIMER2_DIV,
227 }
228#endif
229#else /* CPU_ATMEGA8 */
230 {
231 .dev = MINI_TIMER2,
232 .pin_ch = PWM_PINS_CH0,
233 .div = MINI_TIMER2_DIV,
234 },
235#endif
236 };
237
238 #define PWM_NUMOF ARRAY_SIZE(pwm_conf)
239#endif
240#endif /* PWM_NUMOF */
243#ifdef __cplusplus
244}
245#endif
246
247#endif /* PERIPH_CONF_ATMEGA_COMMON_H */
PWM device configuration.
mini_timer_t * dev
Timer used.