summaryrefslogtreecommitdiff
path: root/nuttx/configs/sam4l-xplained/src/sam4l-xplained.h
blob: bbb88b81151ed685baa712b1851f3aa36b73362a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
/************************************************************************************
 * configs/sam4l-xplained/src/sam4l-xplained.h
 *
 *   Copyright (C) 2013 Gregory Nutt. All rights reserved.
 *   Author: Gregory Nutt <gnutt@nuttx.org>
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in
 *    the documentation and/or other materials provided with the
 *    distribution.
 * 3. Neither the name NuttX nor the names of its contributors may be
 *    used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 *
 ************************************************************************************/

#ifndef __CONFIGS_SAM4L_XPLAINED_SRC_SAM4L_XPLAINED_H
#define __CONFIGS_SAM4L_XPLAINED_SRC_SAM4L_XPLAINED_H

/************************************************************************************
 * Included Files
 ************************************************************************************/

#include <nuttx/config.h>
#include <nuttx/compiler.h>

#include <stdint.h>

#include <arch/irq.h>
#include <nuttx/irq.h>

#include "chip/sam_pinmap.h"

/************************************************************************************
 * Pre-processor Definitions
 ************************************************************************************/
/* LEDs: There are three LEDs on board the SAM4L Xplained Pro board:  The EDBG
 * controls two of the LEDs, a power LED and a status LED.  There is only
 * one user controllable LED, a yellow LED labeled LED0 near the SAM4L USB
 * connector.
 *
 * This LED is controlled by PC07 and LED0 can be activated by driving the
 * PC07 to GND.
 *
 * When CONFIG_ARCH_LEDS is defined in the NuttX configuration, NuttX will
 * control LED0 as follows:
 *
 *   SYMBOL              Meaning                 LED0
 *   ------------------- ----------------------- ------
 *   LED_STARTED         NuttX has been started  OFF
 *   LED_HEAPALLOCATE    Heap has been allocated OFF
 *   LED_IRQSENABLED     Interrupts enabled      OFF
 *   LED_STACKCREATED    Idle stack created      ON
 *   LED_INIRQ           In an interrupt         N/C
 *   LED_SIGNAL          In a signal handler     N/C
 *   LED_ASSERTION       An assertion failed     N/C
 *   LED_PANIC           The system has crashed  FLASH
 *
 * Thus is LED0 is statically on, NuttX has successfully  booted and is,
 * apparently, running normmally.  If LED0 is flashing at approximately
 * 2Hz, then a fatal error has been detected and the system has halted.
 */

#define GPIO_LED0     (GPIO_OUTPUT | GPIO_PULL_NONE | GPIO_OUTPUT_SET | \
                       GPIO_PORTC | GPIO_PIN7)

/* QTouch button: The SAM4L Xplained Pro kit has one QTouch button.  The connection
 * to the SAM4L is:
 *
 *   PC13 CATB_SENSE15
 *   PC14 CATB_DIS
 */

/* Mechanical buttons:
 *
 * The SAM4L Xplained Pro contains two mechanical buttons. One button is the
 * RESET button connected to the SAM4L reset line and the other is a generic user
 * configurable button. When a button is pressed it will drive the I/O line to GND.
 *
 *   PC24 SW0
 */

#define GPIO_SW0      (GPIO_INTERRUPT | GPIO_PULL_UP | GPIO_GLITCH_FILTER | \
                       GPIO_PORTC | GPIO_PIN24)
#define IRQ_SW0       SAM_IRQ_PC24

/* LCD1
 *
 * EXT5  SAM4L BOARD     LCD1     SHARED
 * PIN    PIN  FUNCTION  FUNCTION WITH
 *  1    PA09  COM3      COM3     EXT3
 *  2    PA10  COM2      COM2     EXT3
 *  3    PA11  COM1      COM1     EXT4
 *  4    PA12  COM0      COM0     EXT4
 *  5    PC15  SEG0      SEG0     EXT3
 *  6    PC16  SEG1      SEG1     EXT3
 *  7    PC17  SEG2      SEG2     EXT4
 *  8    PC18  SEG3      SEG3     EXT4
 *  9    PC19  SEG4      SEG4
 *  10   PA13  SEG5      SEG5     EXT4
 *  11   PA14  SEG6      SEG6
 *  12   PA15  SEG7      SEG7     EXT4
 *  13   PA16  SEG8      SEG8     EXT4
 *  14   PA17  SEG9      SEG9     EXT3
 *  15   PC20  SEG10     SEG10
 *  16   PC21  SEG11     SEG11
 *  17   PC22  SEG12     SEG12
 *  18   PC23  SEG13     SEG13
 *  19   PB08  SEG14     SEG14
 *  20   PB09  SEG15     SEG15
 *  21   PB10  SEG16     SEG16    EXT2
 *  22   PB11  SEG17     SEG17    EXT2
 *  23   PA18  SEG18     SEG18    EXT3-4
 *  24   PA19  SEG19     SEG19    EXT3-4
 *  25   PA20  SEG20     SEG20    EXT3-4
 *  26   PB07  SEG21     SEG21
 *  27   PB06  SEG22     SEG22
 *  28   PA08  SEG23     SEG32    EXT3
 *  29   PC24  SEG24     N/C
 *  30   PC25  SEG25     N/C      EXT1
 *  31   PC26  SEG26     N/C      EXT2-3
 *  32   PC27  SEG27     N/C      EXT2-3
 *  33   PC28  SEG28     N/C
 *  34   PC29  SEG29     N/C
 *  35   PC30  SEG30     N/C      EXT1-2
 *  36   PC31  SEG31     N/C
 *  37   PB12  SEG32     N/C      EXT1
 *  38   PB13  SEG33     N/C      EXT1
 *  39   PA21  SEG34     N/C      EXT1-2
 *  40   PA22  SEG35     N/C      EXT1-2
 *  41   PB14  SEG36     N/C      EXT2-4
 *  42   PB15  SEG37     N/C      EXT2-4
 *  43   PA23  SEG38     N/C      EXT1
 *  44   PA24  SEG39     N/C      EXT1
 *  45   ---   N/C       N/C
 *  46   ---   N/C       N/C
 *  47   ---   VCC_P3V3  BL V+
 *  48   ---   GND       BL V-
 *  49   PC05  BL        BL CTRL  EXT2
 *  50   ---   ID        ID
 *  51   ---   GND       GND
 *
 * The backlight control is active high.
 */

#ifdef CONFIG_SAM4L_XPLAINED_SLCD1MODULE

#  ifndef CONFIG_SAM34_LCDCA
#    error CONFIG_SAM34_LCDCA is required to use the LCD1 module
#  endif

#  define GPIO_LCD1_BL (GPIO_OUTPUT | GPIO_PULL_NONE | GPIO_OUTPUT_CLEAR | \
                        GPIO_PORTC | GPIO_PIN5)
#endif

/* I/O1
 *
 * Support for the microSD card slot on the I/O1 module.  The I/O1 requires
 * SPI support and two GPIOs.    These the GPIOs will vary if the I/O1
 * is installed on the EXT1 or EXT2 connector:
 *
 *
 *   PIN EXT1           EXT2            Description
 *   --- -------------- --------------- -------------------------------------
 *   15  PC03 SPI/NPCS0 PB11 SPI/NPCS2  Active low chip select OUTPUT, pulled
 *                                      high on board.
 *   10  PB13 SPI/NPCS1 PC09 GPIO       Active low card detect INPUT, must
 *                                      use internal pull-up.
 */

#ifdef CONFIG_SAM4L_XPLAINED_IOMODULE

#  ifndef CONFIG_SAM34_SPI0
#    error CONFIG_SAM34_SPI0 is required to use the I/O1 module
#  endif

#  if defined(CONFIG_SAM4L_XPLAINED_IOMODULE_EXT1)

#    if defined(CONFIG_SAM4L_XPLAINED_OLED1MODULE) && \
        defined(CONFIG_SAM4L_XPLAINED_OLED1MODULE_EXT1)
#      error I/O1 and OLED1 modules cannot both reside in EXT1
#    endif

#    define GPIO_SD_CD (GPIO_INTERRUPT | GPIO_INT_CHANGE | GPIO_PULL_UP | \
                        GPIO_GLITCH_FILTER | GPIO_PORTB | GPIO_PIN13)
#    define IRQ_SD_CD   SAM_IRQ_PB13

#    define GPIO_SD_CS (GPIO_OUTPUT | GPIO_PULL_NONE | GPIO_OUTPUT_SET | \
                        GPIO_PORTC | GPIO_PIN3)
#    define SD_CSNO    0

#  elif defined(CONFIG_SAM4L_XPLAINED_IOMODULE_EXT2)

#    ifndef CONFIG_SAM4L_XPLAINED_SLCD1MODULE
#      error I/O1 cannot be in EXT2 if the LCD1 module is connected
#    endif

#    if defined(CONFIG_SAM4L_XPLAINED_OLED1MODULE) && \
        defined(CONFIG_SAM4L_XPLAINED_OLED1MODULE_EXT2)
#      error I/O1 and OLED1 modules cannot both reside in EXT2
#    endif

#    define GPIO_CD   (GPIO_INTERRUPT | GPIO_INT_CHANGE | GPIO_PULL_UP | \
                       GPIO_GLITCH_FILTER | GPIO_PORTC | GPIO_PIN9)
#    define IRQ_CD     SAM_IRQ_PC9

#    define GPIO_SD_CS (GPIO_OUTPUT | GPIO_PULL_NONE | GPIO_OUTPUT_SET | \
                        GPIO_PORTB | GPIO_PIN11)
#    define SD_CSNO    2

#  else
#    error Which connector is the I/O1 module installed in?
#  endif
#endif

/* OLED1
 *
 * Support for the microSD card slot on the I/O1 module.  The I/O1 requires
 * SPI support and three output GPIOs.  These the GPIOs will vary if the OLED1
 * is installed on the EXT1 or EXT2 connector:
 *
 *
 *   PIN EXT1           EXT2            Description
 *   --- -------------- --------------- -------------------------------------
 *   5   PB12 GPIO      PC08 GPIO       DATA_CMD_SEL
 *   10  PB13 SPI/NPCS1 PC09 GPIO       DISPLAY_RESET. Active low.
 *   15  PC03 SPI/NPCS0 PB11 SPI/NPCS2  DISPLAY_SS.  Active low.
 */

#ifdef CONFIG_SAM4L_XPLAINED_OLED1MODULE

#  ifndef CONFIG_SAM34_SPI0
#    error CONFIG_SAM34_SPI0 is required to use the OLED1 module
#  endif

#  ifndef CONFIG_SPI_CMDDATA
#    error CONFIG_SPI_CMDDATA is required to use the OLED1 module
#  endif

#  ifndef CONFIG_LCD_SSD1306
#    error CONFIG_LCD_SSD1306 is required to use the OLED1 module
#  endif

#  ifndef CONFIG_LCD_UG2832HSWEG04
#    error CONFIG_LCD_UG2832HSWEG04 is required to use the OLED1 module
#  endif

#  if defined(CONFIG_SAM4L_XPLAINED_OLED1MODULE_EXT1)

#    if defined(CONFIG_SAM4L_XPLAINED_IOMODULE) && \
        defined(CONFIG_SAM4L_XPLAINED_IOMODULE_EXT1)
#      error OLED1 and I/O1 modules cannot both reside in EXT1
#    endif

#    define GPIO_OLED_DATA (GPIO_OUTPUT | GPIO_PULL_NONE | GPIO_OUTPUT_CLEAR | \
                            GPIO_PORTB | GPIO_PIN12)
#    define GPIO_OLED_RST  (GPIO_OUTPUT | GPIO_PULL_NONE | GPIO_OUTPUT_CLEAR | \
                            GPIO_PORTB | GPIO_PIN13)
#    define GPIO_OLED_CS   (GPIO_OUTPUT | GPIO_PULL_NONE | GPIO_OUTPUT_SET | \
                            GPIO_PORTC | GPIO_PIN3)
#    define OLED_CSNO       0

#  elif defined(CONFIG_SAM4L_XPLAINED_OLED1MODULE_EXT2)

#    ifndef CONFIG_SAM4L_XPLAINED_SLCD1MODULE
#      error OLED1 cannot be in EXT2 if the LCD1 module is connected
#    endif

#    if defined(CONFIG_SAM4L_XPLAINED_IOMODULE) && \
        defined(CONFIG_SAM4L_XPLAINED_IOMODULE_EXT2)
#      error OLED1 and I/O1 modules cannot both reside in EXT2
#    endif

#    define GPIO_OLED_DATA (GPIO_OUTPUT | GPIO_PULL_NONE | GPIO_OUTPUT_CLEAR | \
                            GPIO_PORTC | GPIO_PIN8)
#    define GPIO_OLED_RST  (GPIO_OUTPUT | GPIO_PULL_NONE | GPIO_OUTPUT_CLEAR | \
                            GPIO_PORTc | GPIO_PIN9)
#    define GPIO_OLED_CS   (GPIO_OUTPUT | GPIO_PULL_NONE | GPIO_OUTPUT_SET | \
                            GPIO_PORTB | GPIO_PIN11)
#    define OLED_CSNO      2

#  else
#    error Which connector is the OLED1 module installed in?
#  endif
#endif

#if defined(CONFIG_LCD_UG2864AMBAG01) || defined(CONFIG_LCD_UG2864HSWEG01)
#    define GPIO_SD_CS (GPIO_OUTPUT | GPIO_PULL_NONE | GPIO_OUTPUT_SET | \
                        GPIO_PORTB | GPIO_PIN11)
#endif

/************************************************************************************
 * Public Types
 ************************************************************************************/

/************************************************************************************
 * Public data
 ************************************************************************************/

#ifndef __ASSEMBLY__

/************************************************************************************
 * Public Functions
 ************************************************************************************/

/************************************************************************************
 * Name: sam_spiinitialize
 *
 * Description:
 *   Called to configure SPI chip select GPIO pins for the SAM3U-EK board.
 *
 ************************************************************************************/

void weak_function sam_spiinitialize(void);

/************************************************************************************
 * Name: sam_sdinitialize
 *
 * Description:
 *   Initialize the SPI-based SD card.  Requires CONFIG_SAM4L_XPLAINED_IOMODULE=y,
 *   CONFIG_DISABLE_MOUNTPOINT=n, CONFIG_MMCSD=y, and CONFIG_SAM34_SPI0=y
 *
 ************************************************************************************/

#if defined(CONFIG_SAM34_SPI0) && defined(CONFIG_SAM4L_XPLAINED_IOMODULE)
int sam_sdinitialize(int minor);
#endif

/****************************************************************************
 * Name: sam_slcd_initialize
 *
 * Description:
 *   Initialize the SAM4L Xplained Pro LCD hardware and register the character
 *   driver as /dev/slcd.
 *
 ****************************************************************************/

#if defined(CONFIG_SAM34_LCDCA) && defined(CONFIG_SAM4L_XPLAINED_SLCD1MODULE)
int sam_slcd_initialize(void);
#endif

/************************************************************************************
 * Name: up_ledinit
 ************************************************************************************/

#ifdef CONFIG_ARCH_LEDS
void up_ledinit(void);
#endif

#endif /* __ASSEMBLY__ */
#endif /* __CONFIGS_SAM4L_XPLAINED_SRC_SAM4L_XPLAINED_H */