From 0a9fab9abe80fe61e9c068e78c517c45d669935f Mon Sep 17 00:00:00 2001 From: Stefan Richter Date: Wed, 22 Jun 2011 23:50:44 +0200 Subject: HACK: Cut power on release of power button --- nuttx/arch/arm/src/calypso/calypso_keypad.c | 30 +++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/nuttx/arch/arm/src/calypso/calypso_keypad.c b/nuttx/arch/arm/src/calypso/calypso_keypad.c index c164baffe6..4a63a70cc3 100644 --- a/nuttx/arch/arm/src/calypso/calypso_keypad.c +++ b/nuttx/arch/arm/src/calypso/calypso_keypad.c @@ -50,6 +50,33 @@ #include +/**************************************************************************** + * Power control + ****************************************************************************/ + +#include +#include + +int poweroff(void) +{ + uint16_t tx; + struct spi_dev_s *spi = up_spiinitialize(0); + + printf("cutting power...\n\n"); + usleep(10000); + + SPI_SETBITS(spi, 16); + + tx = (1 << 6) | (1 << 1); + SPI_SNDBLOCK(spi, &tx, 1); + + tx = (1 << 6) | (30 << 1); + SPI_SNDBLOCK(spi, &tx, 1); + + return 0; +} + + /**************************************************************************** * HW access ****************************************************************************/ @@ -135,6 +162,9 @@ static int pwr_btn_dec(uint32_t *state, uint8_t reg, char *buf, size_t *len) } else { /* Check for released power button. */ if(*state & 0x80000000) { + /* XXX: just cut power, pending better solution */ + poweroff(); + buf[0] = 'Z'; *len = 1; -- cgit v1.2.3