boards/arm/s32k1xx/s32k118evb: Implement board support for LEDs and buttons. This is taken from the Freedom-K66f with has the same LED and button configuation as the S32K116EVB and uses the same GPIO IP.

boards/arm/s32k1xx/s32k118evb/include/board.h:  Add LPUART0 pin disambiguation.

arch/arm/src/s32k1xx/hardware:  Add pin mux definitions for S32K116, 118, 142, 144, 146, and 148.

arch/arm/src/s32k1xx/s32k1xx_pin.c and .h:  Add support for PIDR register that disables a gneral purpose pin from acting as an input.

arch/arm/src/s32k1xx/s32k1xx_pin.c and .h:  The device does not support slew rate controls or open drain (on all the pins).  Only pins that are configured for a protocol that requires open-drain (e.g;, LPI2C, LPUART single-wire) will work in open-drain mode.
This commit is contained in:
Gregory Nutt
2019-08-18 12:02:54 -06:00
parent ac36b1de3b
commit db0641556e
16 changed files with 3739 additions and 269 deletions
+14 -12
View File
@@ -50,18 +50,20 @@ LEDs and Buttons
the s32k118evb. The following definitions describe how NuttX controls the
LEDs:
======================+========+========+=========
RED GREEN BLUE
======================+========+========+=========
LED_STARTED OFF OFF OFF
LED_HEAPALLOCATE OFF OFF OFF
LED_IRQSENABLED OFF OFF OFF
LED_STACKCREATED OFF ON OFF
LED_INIRQ OFF N/C ON
LED_SIGNAL OFF N/C ON
LED_ASSERTION OFF N/C ON
LED_PANIC Flashing OFF N/C
======================+========+========+=========
==========================================+========+========+=========
RED GREEN BLUE
==========================================+========+========+=========
LED_STARTED NuttX has been started OFF OFF OFF
LED_HEAPALLOCATE Heap has been allocated OFF OFF ON
LED_IRQSENABLED Interrupts enabled OFF OFF ON
LED_STACKCREATED Idle stack created OFF ON OFF
LED_INIRQ In an interrupt (no change)
LED_SIGNAL In a signal handler (no change)
LED_ASSERTION An assertion failed (no change)
LED_PANIC The system has crashed FLASH OFF OFF
LED_IDLE S32K118EVN in sleep mode (no change)
==========================================+========+========+=========
Buttons
-------
+30 -16
View File
@@ -77,30 +77,36 @@
/* LED index values for use with board_userled() */
#define BOARD_RED 0
#define BOARD_BLUE 1
#define BOARD_GREEN 2
#define BOARD_NLEDS 3
#define BOARD_LED_R 0
#define BOARD_LED_G 1
#define BOARD_LED_B 2
#define BOARD_NLEDS 3
/* LED bits for use with board_userled_all() */
#define BOARD_REDLED_BIT (1 << BOARD_RED)
#define BOARD_GREENLED_BIT (1 << BOARD_BLUE)
#define BOARD_BLUELED_BIT (1 << BOARD_GREEN)
#define BOARD_LED_R_BIT (1 << BOARD_LED_R)
#define BOARD_LED_G_BIT (1 << BOARD_LED_G)
#define BOARD_LED_B_BIT (1 << BOARD_LED_B)
/* If CONFIG_ARCH_LEDs is defined, then NuttX will control the LEDs on board
* the s32k118evb. The following definitions describe how NuttX controls the
* LEDs:
*
*
* SYMBOL Meaning LED state
* RED GREEN BLUE
* ------------------- ---------------------------- -----------------
*/
/* RED GREEN BLUE */
#define LED_STARTED 0 /* OFF OFF OFF */
#define LED_HEAPALLOCATE 0 /* OFF OFF OFF */
#define LED_IRQSENABLED 0 /* OFF OFF OFF */
#define LED_STACKCREATED 1 /* OFF ON OFF */
#define LED_INIRQ 2 /* OFF N/C ON */
#define LED_SIGNAL 2 /* OFF N/C ON */
#define LED_ASSERTION 2 /* OFF N/C ON */
#define LED_PANIC 3 /* Flashing OFF N/C */
#define LED_STARTED 1 /* NuttX has been started OFF OFF OFF */
#define LED_HEAPALLOCATE 2 /* Heap has been allocated OFF OFF ON */
#define LED_IRQSENABLED 0 /* Interrupts enabled OFF OFF ON */
#define LED_STACKCREATED 3 /* Idle stack created OFF ON OFF */
#define LED_INIRQ 0 /* In an interrupt (no change) */
#define LED_SIGNAL 0 /* In a signal handler (no change) */
#define LED_ASSERTION 0 /* An assertion failed (no change) */
#define LED_PANIC 4 /* The system has crashed FLASH OFF OFF */
#undef LED_IDLE /* S32K118EVN in sleep mode (Not used) */
/* Button definitions *******************************************************/
@@ -119,6 +125,14 @@
/* Alternate function pin selections ****************************************/
/* By default, the serial console will be provided on the OpenSDA VCOM port:
*
* OpenSDA UART TX PTB1(LPUART0_TX)
* OpenSDA UART RX PTB0(LPUART0_RX)
*/
#define PIN_LPUART0_RX PIN_LPUART0_RX_1 /* PTB0 */
#define PIN_LPUART0_TX PIN_LPUART0_TX_1 /* PTB1 */
/* DMA Channel/Stream Selections ********************************************/
@@ -32,6 +32,30 @@
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
/* The S32K118EVB has one RGB LED:
*
* RedLED PTD16 (FTM0CH1)
* GreenLED PTD15 (FTM0CH0)
* BlueLED PTE8 (FTM0CH6)
*
*
* If CONFIG_ARCH_LEDs is defined, then NuttX will control the LED on board
* the Freedom K66F. The following definitions describe how NuttX controls
* the LEDs:
*
* SYMBOL Meaning LED state
* RED GREEN BLUE
* ------------------- ----------------------- -----------------
* LED_STARTED NuttX has been started OFF OFF OFF
* LED_HEAPALLOCATE Heap has been allocated OFF OFF ON
* LED_IRQSENABLED Interrupts enabled OFF OFF ON
* LED_STACKCREATED Idle stack created OFF ON OFF
* LED_INIRQ In an interrupt (no change)
* LED_SIGNAL In a signal handler (no change)
* LED_ASSERTION An assertion failed (no change)
* LED_PANIC The system has crashed FLASH OFF OFF
* LED_IDLE K66 is in sleep mode (Optional, not used)
*/
/****************************************************************************
* Included Files
@@ -46,18 +70,28 @@
#include <nuttx/board.h>
#include <arch/board/board.h>
#include "chip.h"
#include "up_arch.h"
#include "up_internal.h"
#include "s32k1xx_pin.h"
#include "s32k118evb.h"
#include <arch/board/board.h>
#ifdef CONFIG_ARCH_LEDS
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/* Summary of all possible settings */
#define LED_NOCHANGE 0 /* LED_IRQSENABLED, LED_INIRQ, LED_SIGNAL, LED_ASSERTION */
#define LED_OFF_OFF_OFF 1 /* LED_STARTED */
#define LED_OFF_OFF_ON 2 /* LED_HEAPALLOCATE */
#define LED_OFF_ON_OFF 3 /* LED_STACKCREATED */
#define LED_ON_OFF_OFF 4 /* LED_PANIC */
/****************************************************************************
* Private Data
****************************************************************************/
@@ -77,6 +111,10 @@
void board_autoled_initialize(void)
{
/* Configure LED GPIOs for output */
s32k1xx_pinconfig(GPIO_LED_R);
s32k1xx_pinconfig(GPIO_LED_G);
s32k1xx_pinconfig(GPIO_LED_B);
}
/****************************************************************************
@@ -85,6 +123,35 @@ void board_autoled_initialize(void)
void board_autoled_on(int led)
{
if (led != LED_NOCHANGE)
{
bool redoff = true;
bool greenoff = true;
bool blueoff = true;
switch (led)
{
default:
case LED_OFF_OFF_OFF:
break;
case LED_OFF_OFF_ON:
blueoff = false;
break;
case LED_OFF_ON_OFF:
greenoff = false;
break;
case LED_ON_OFF_OFF:
redoff = false;
break;
}
s32k1xx_gpiowrite(GPIO_LED_R, redoff);
s32k1xx_gpiowrite(GPIO_LED_G, greenoff);
s32k1xx_gpiowrite(GPIO_LED_B, blueoff);
}
}
/****************************************************************************
@@ -93,6 +160,12 @@ void board_autoled_on(int led)
void board_autoled_off(int led)
{
if (led == LED_ON_OFF_OFF)
{
s32k1xx_gpiowrite(GPIO_LED_R, true);
s32k1xx_gpiowrite(GPIO_LED_G, true);
s32k1xx_gpiowrite(GPIO_LED_B, true);
}
}
#endif /* CONFIG_ARCH_LEDS */
@@ -32,6 +32,11 @@
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
/* The S32K118EVB supports two buttons:
*
* SW2 PTD3
* SW3 PTD5
*/
/****************************************************************************
* Included Files
@@ -44,15 +49,13 @@
#include <nuttx/arch.h>
#include <nuttx/board.h>
#include <arch/board/board.h>
#include "s32k1xx_pin.h"
#include "s32k118evb.h"
#ifdef CONFIG_ARCH_BUTTONS
#include <arch/board/board.h>
/****************************************************************************
* Private Data
****************************************************************************/
#ifdef CONFIG_ARCH_BUTTONS
/****************************************************************************
* Public Functions
@@ -72,6 +75,9 @@
void board_button_initialize(void)
{
/* Configure the GPIO pins as interrupting inputs. */
s32k1xx_pinconfig(GPIO_SW2);
s32k1xx_pinconfig(GPIO_SW3);
}
/****************************************************************************
@@ -80,7 +86,19 @@ void board_button_initialize(void)
uint32_t board_buttons(void)
{
return 0;
uint32_t ret = 0;
if (s32k1xx_gpioread(GPIO_SW2))
{
ret |= BUTTON_SW2_BIT;
}
if (s32k1xx_gpioread(GPIO_SW3))
{
ret |= BUTTON_SW3_BIT;
}
return ret;
}
/************************************************************************************
@@ -108,7 +126,39 @@ uint32_t board_buttons(void)
#ifdef CONFIG_ARCH_IRQBUTTONS
int board_button_irq(int id, xcpt_t irqhandler, FAR void *arg)
{
return -ENOSYS;
uint32_t pinset;
int ret;
/* Map the button id to the GPIO bit set. */
if (id == BUTTON_SW2)
{
pinset = GPIO_SW2;
}
else if (id == BUTTON_SW3)
{
pinset = GPIO_SW3;
}
else
{
return -EINVAL;
}
/* The button has already been configured as an interrupting input (by
* board_button_initialize() above).
*
* Attach the new button handler.
*/
ret = s32k1xx_pinirqattach(pinset, irqhandler, NULL);
if (ret >= 0)
{
/* Then make sure that interrupts are enabled on the pin */
s32k1xx_pinirqenable(pinset);
}
return ret;
}
#endif
#endif /* CONFIG_ARCH_BUTTONS */
@@ -44,31 +44,17 @@
#include <debug.h>
#include <nuttx/board.h>
#include <arch/board/board.h>
#include "up_arch.h"
#include "up_internal.h"
#include "s32k1xx_pin.h"
#include "s32k118evb.h"
#include <arch/board/board.h>
#ifndef CONFIG_ARCH_LEDS
/****************************************************************************
* Private Data
****************************************************************************/
/****************************************************************************
* Private Function Prototypes
****************************************************************************/
/****************************************************************************
* Private Data
****************************************************************************/
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/
@@ -79,7 +65,11 @@
void board_userled_initialize(void)
{
/* Configure LED GPIOs for output */
/* Configure LED GPIOs for output */
s32k1xx_pinconfig(GPIO_LED_R);
s32k1xx_pinconfig(GPIO_LED_G);
s32k1xx_pinconfig(GPIO_LED_B);
}
/****************************************************************************
@@ -88,6 +78,26 @@ void board_userled_initialize(void)
void board_userled(int led, bool ledon)
{
uint32_t ledcfg;
if (led == BOARD_LED_R)
{
ledcfg = GPIO_LED_R;
}
else if (led == BOARD_LED_G)
{
ledcfg = GPIO_LED_G;
}
else if (led == BOARD_LED_B)
{
ledcfg = GPIO_LED_B;
}
else
{
return;
}
s32k1xx_gpiowrite(ledcfg, !ledon); /* Low illuminates */
}
/****************************************************************************
@@ -96,6 +106,11 @@ void board_userled(int led, bool ledon)
void board_userled_all(uint8_t ledset)
{
/* Low illuminates */
s32k1xx_gpiowrite(GPIO_LED_R, (ledset & BOARD_LED_R_BIT) == 0);
s32k1xx_gpiowrite(GPIO_LED_G, (ledset & BOARD_LED_G_BIT) == 0);
s32k1xx_gpiowrite(GPIO_LED_B, (ledset & BOARD_LED_B_BIT) == 0);
}
#endif /* !CONFIG_ARCH_LEDS */
+14 -2
View File
@@ -45,6 +45,7 @@
#include <stdint.h>
#include "hardware/s32k1xx_pinmux.h"
#include "s32k1xx_periphclocks.h"
/****************************************************************************
@@ -54,15 +55,26 @@
/* Configuration ************************************************************/
/* S32K118EVB GPIOs *********************************************************/
/* LEDs. The S32K118EVB has one RGB LED:
*
* RedLED PTD16 (FTM0CH1)
* GreenLED PTD15 (FTM0CH0)
* BlueLED PTE8 (FTM0CH6)
* GreenLED PTD15 (FTM0 CH0)
*/
/* BUTTONS */
#define GPIO_LED_R (PIN_PTD16 | GPIO_LOWDRIVE | GPIO_OUTPUT_ONE)
#define GPIO_LED_G (PIN_PTD15 | GPIO_LOWDRIVE | GPIO_OUTPUT_ONE)
#define GPIO_LED_B (PIN_PTE8 | GPIO_LOWDRIVE | GPIO_OUTPUT_ONE)
/* Buttons. The S32K118EVB supports two buttons:
*
* SW2 PTD3
* SW3 PTD5
*/
#define GPIO_SW2 (PIN_PTD3 | PIN_INT_BOTH)
#define GPIO_SW3 (PIN_PTD5 | PIN_INT_BOTH)
/* SPI chip selects */