Refactored: function names, coding style
This commit is contained in:
parent
44e0a837a8
commit
2ae38b6bc6
@ -182,14 +182,6 @@ extern "C" {
|
|||||||
* Public Function Prototypes
|
* Public Function Prototypes
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
|
|
||||||
/*******************************************************************************
|
|
||||||
* Name: stm32_led_initialize
|
|
||||||
*
|
|
||||||
* Description:
|
|
||||||
* Initializes board specific LEDS
|
|
||||||
******************************************************************************/
|
|
||||||
void stm32_led_initialize(void);
|
|
||||||
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Name: stm32_boardinitialize
|
* Name: stm32_boardinitialize
|
||||||
*
|
*
|
||||||
@ -199,6 +191,7 @@ void stm32_led_initialize(void);
|
|||||||
* has been configured and mapped but before any devices have been
|
* has been configured and mapped but before any devices have been
|
||||||
* initialized.
|
* initialized.
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
|
|
||||||
EXTERN void stm32_boardinitialize(void);
|
EXTERN void stm32_boardinitialize(void);
|
||||||
|
|
||||||
#undef EXTERN
|
#undef EXTERN
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/*******************************************************************************
|
/*****************************************************************************
|
||||||
* configs/stm32butterfly2/src/stm32_adc.c
|
* configs/stm32butterfly2/src/stm32_adc.c
|
||||||
*
|
*
|
||||||
* Copyright (C) 2016 Michał Łyszczek. All rights reserved.
|
* Copyright (C) 2016 Michał Łyszczek. All rights reserved.
|
||||||
@ -30,22 +30,28 @@
|
|||||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
* POSSIBILITY OF SUCH DAMAGE.
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
*
|
****************************************************************************/
|
||||||
******************************************************************************/
|
|
||||||
|
|
||||||
/*******************************************************************************
|
/*****************************************************************************
|
||||||
* Included Files
|
* Included Files
|
||||||
******************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include <chip.h>
|
#include <chip.h>
|
||||||
#include <debug.h>
|
#include <debug.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <nuttx/config.h>
|
|
||||||
#include <stm32_adc.h>
|
|
||||||
|
|
||||||
/*******************************************************************************
|
#include "stm32_adc.h"
|
||||||
|
|
||||||
|
/*****************************************************************************
|
||||||
* Public Functions
|
* Public Functions
|
||||||
******************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
|
/*****************************************************************************
|
||||||
|
* Name: board_adc_setup
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Function initializes channel 1 of adc1 and registers device as /dev/adc0
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
int board_adc_setup(void)
|
int board_adc_setup(void)
|
||||||
{
|
{
|
||||||
@ -60,8 +66,7 @@ int board_adc_setup(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
stm32_configgpio(GPIO_ADC12_IN10);
|
stm32_configgpio(GPIO_ADC12_IN10);
|
||||||
adc = stm32_adcinitialize(1, channel, 1);
|
if ((adc = stm32_adcinitialize(1, channel, 1)) == NULL)
|
||||||
if (adc == NULL)
|
|
||||||
{
|
{
|
||||||
aerr("ERROR: Failed to get adc interface\n");
|
aerr("ERROR: Failed to get adc interface\n");
|
||||||
return -ENODEV;
|
return -ENODEV;
|
||||||
@ -76,3 +81,4 @@ int board_adc_setup(void)
|
|||||||
initialized = true;
|
initialized = true;
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/*******************************************************************************
|
/*****************************************************************************
|
||||||
* configs/stm32butterfly2/src/boot.c
|
* configs/stm32butterfly2/src/boot.c
|
||||||
*
|
*
|
||||||
* Copyright (C) 2016 Michał Łyszczek. All rights reserved.
|
* Copyright (C) 2016 Michał Łyszczek. All rights reserved.
|
||||||
@ -30,23 +30,28 @@
|
|||||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
* POSSIBILITY OF SUCH DAMAGE.
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
*
|
****************************************************************************/
|
||||||
******************************************************************************/
|
|
||||||
|
|
||||||
/*******************************************************************************
|
/*****************************************************************************
|
||||||
* Included Files
|
* Included Files
|
||||||
******************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include <nuttx/config.h>
|
#include <nuttx/config.h>
|
||||||
#include <arch/board/board.h>
|
#include <arch/board/board.h>
|
||||||
#include <syslog.h>
|
#include <syslog.h>
|
||||||
|
|
||||||
#include "stm32_gpio.h"
|
|
||||||
#include "stm32_butterfly2.h"
|
#include "stm32_butterfly2.h"
|
||||||
|
|
||||||
/*******************************************************************************
|
/*****************************************************************************
|
||||||
* Public Functions
|
* Public Functions
|
||||||
******************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
|
/*****************************************************************************
|
||||||
|
* Name: stm32_boardinitialize
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Initializes low level pins for the drivers.
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
void stm32_boardinitialize(void)
|
void stm32_boardinitialize(void)
|
||||||
{
|
{
|
||||||
@ -55,20 +60,35 @@ void stm32_boardinitialize(void)
|
|||||||
stm32_usb_initialize();
|
stm32_usb_initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************
|
||||||
|
* Name: board_app_initialize
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Initializes upper half drivers with board specific settings
|
||||||
|
*
|
||||||
|
* Returned value:
|
||||||
|
* 0 on sucess or errno value of failed init function.
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
int board_app_initialize(uintptr_t arg)
|
int board_app_initialize(uintptr_t arg)
|
||||||
{
|
{
|
||||||
int rv;
|
int rv = 0;
|
||||||
if ((rv = stm32_sdinitialize(CONFIG_NSH_MMCSDMINOR)) < 0)
|
|
||||||
|
#ifdef CONFIG_MMCSD
|
||||||
|
if ((rv = stm32_mmcsd_initialize(CONFIG_NSH_MMCSDMINOR)) < 0)
|
||||||
{
|
{
|
||||||
syslog(LOG_ERR, "Failed to initialize SD slot %d: %d\n");
|
syslog(LOG_ERR, "Failed to initialize SD slot %d: %d\n");
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef CONFIG_USBHOST
|
||||||
if ((rv = stm32_usbhost_initialize()) < 0)
|
if ((rv = stm32_usbhost_initialize()) < 0)
|
||||||
{
|
{
|
||||||
syslog(LOG_ERR, "ERROR: Failed to initialize USB host: %d\n", rv);
|
syslog(LOG_ERR, "ERROR: Failed to initialize USB host: %d\n", rv);
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
return 0;
|
return rv;
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,6 @@
|
|||||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
* POSSIBILITY OF SUCH DAMAGE.
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
*
|
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
@ -59,6 +58,15 @@
|
|||||||
* Public Functions
|
* Public Functions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
|
/*****************************************************************************
|
||||||
|
* Name: stm32_led_initialize
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Initializes low level gpio pins for board LEDS
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
void stm32_led_initialize(void);
|
||||||
|
|
||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
* Name: stm32_spidev_initialize
|
* Name: stm32_spidev_initialize
|
||||||
*
|
*
|
||||||
@ -70,17 +78,25 @@
|
|||||||
* itself.
|
* itself.
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifdef CONFIG_STM32_SPI1
|
||||||
void stm32_spidev_initialize(void);
|
void stm32_spidev_initialize(void);
|
||||||
|
#else
|
||||||
|
static inline void stm32_spidev_initialize(void);
|
||||||
|
#endif
|
||||||
|
|
||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
* Name: stm32_sdinitialize
|
* Name: stm32_mmcsd_initialize
|
||||||
*
|
*
|
||||||
* Description:
|
* Description:
|
||||||
* Initializes SPI-based SD card
|
* Initializes SPI-based SD card
|
||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
int stm32_sdinitialize(int minor);
|
#ifdef CONFIG_MMCSD
|
||||||
|
int stm32_mmcsd_initialize(int minor);
|
||||||
|
#else
|
||||||
|
static inline int stm32_mmcsd_initialize(int minor);
|
||||||
|
#endif
|
||||||
|
|
||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
* Name: stm32_usb_initialize
|
* Name: stm32_usb_initialize
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*******************************************************************************
|
/*****************************************************************************
|
||||||
* configs/stm32butterfly2/src/led.c
|
* configs/stm32butterfly2/src/stm32_led.c
|
||||||
*
|
*
|
||||||
* Copyright (C) 2016 Michał Łyszczek. All rights reserved.
|
* Copyright (C) 2016 Michał Łyszczek. All rights reserved.
|
||||||
* Author: Michał Łyszczek <michal.lyszczek@gmail.com>
|
* Author: Michał Łyszczek <michal.lyszczek@gmail.com>
|
||||||
@ -31,26 +31,22 @@
|
|||||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
* POSSIBILITY OF SUCH DAMAGE.
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
*
|
*
|
||||||
******************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
/*******************************************************************************
|
/*****************************************************************************
|
||||||
* Included Files
|
* Included Files
|
||||||
******************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include <nuttx/config.h>
|
|
||||||
|
|
||||||
#include <stdint.h>
|
|
||||||
#include <stdbool.h>
|
|
||||||
|
|
||||||
#include <nuttx/board.h>
|
#include <nuttx/board.h>
|
||||||
#include <arch/board/board.h>
|
#include <nuttx/config.h>
|
||||||
#include <debug.h>
|
#include <stdbool.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
#include "stm32_gpio.h"
|
#include "stm32_gpio.h"
|
||||||
|
|
||||||
/*******************************************************************************
|
/*****************************************************************************
|
||||||
* Pre-processor definitions
|
* Pre-processor definitions
|
||||||
******************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#define GPIO_LED1 (GPIO_OUTPUT | GPIO_CNF_OUTPP | GPIO_MODE_50MHz |\
|
#define GPIO_LED1 (GPIO_OUTPUT | GPIO_CNF_OUTPP | GPIO_MODE_50MHz |\
|
||||||
GPIO_OUTPUT_SET | GPIO_PORTB | GPIO_PIN0)
|
GPIO_OUTPUT_SET | GPIO_PORTB | GPIO_PIN0)
|
||||||
@ -61,9 +57,9 @@
|
|||||||
#define GPIO_LED4 (GPIO_OUTPUT | GPIO_CNF_OUTPP | GPIO_MODE_50MHz |\
|
#define GPIO_LED4 (GPIO_OUTPUT | GPIO_CNF_OUTPP | GPIO_MODE_50MHz |\
|
||||||
GPIO_OUTPUT_SET | GPIO_PORTC | GPIO_PIN5)
|
GPIO_OUTPUT_SET | GPIO_PORTC | GPIO_PIN5)
|
||||||
|
|
||||||
/*******************************************************************************
|
/*****************************************************************************
|
||||||
* Private Types
|
* Private Types
|
||||||
******************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
/* Identifies led state */
|
/* Identifies led state */
|
||||||
enum led_state
|
enum led_state
|
||||||
@ -72,9 +68,16 @@ enum led_state
|
|||||||
LED_OFF = true
|
LED_OFF = true
|
||||||
};
|
};
|
||||||
|
|
||||||
/*******************************************************************************
|
/*****************************************************************************
|
||||||
* Private Functions
|
* Private Functions
|
||||||
******************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
|
/*****************************************************************************
|
||||||
|
* Name: led_state
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Sets pack of leds to given state
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
static void led_state(enum led_state state, unsigned int leds)
|
static void led_state(enum led_state state, unsigned int leds)
|
||||||
{
|
{
|
||||||
@ -87,7 +90,7 @@ static void led_state(enum led_state state, unsigned int leds)
|
|||||||
{
|
{
|
||||||
stm32_gpiowrite(GPIO_LED2, state);
|
stm32_gpiowrite(GPIO_LED2, state);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (leds & BOARD_LED3_BIT)
|
if (leds & BOARD_LED3_BIT)
|
||||||
{
|
{
|
||||||
stm32_gpiowrite(GPIO_LED3, state);
|
stm32_gpiowrite(GPIO_LED3, state);
|
||||||
@ -99,9 +102,16 @@ static void led_state(enum led_state state, unsigned int leds)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*******************************************************************************
|
/*****************************************************************************
|
||||||
* Public Functions
|
* Public Functions
|
||||||
******************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
|
/*****************************************************************************
|
||||||
|
* Name: stm32_led_initialize
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Initializes low level gpio pins for board LEDS
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
void stm32_led_initialize(void)
|
void stm32_led_initialize(void)
|
||||||
{
|
{
|
||||||
@ -112,6 +122,17 @@ void stm32_led_initialize(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef CONFIG_ARCH_LEDS
|
#ifdef CONFIG_ARCH_LEDS
|
||||||
|
|
||||||
|
/*****************************************************************************
|
||||||
|
* Name: board_autoled_on
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Drives board leds when specific RTOS state led occurs.
|
||||||
|
*
|
||||||
|
* Input parameters:
|
||||||
|
* led - This is actually an RTOS state not led number of anything like that
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
void board_autoled_on(int led)
|
void board_autoled_on(int led)
|
||||||
{
|
{
|
||||||
switch (led)
|
switch (led)
|
||||||
@ -145,6 +166,16 @@ void board_autoled_on(int led)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************
|
||||||
|
* Name: board_autoled_off
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Drives board leds when specific RTOS state led ends
|
||||||
|
*
|
||||||
|
* Input parameters:
|
||||||
|
* led - This is actually an RTOS state not led number of anything like that
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
void board_autoled_off(int led)
|
void board_autoled_off(int led)
|
||||||
{
|
{
|
||||||
switch (led)
|
switch (led)
|
||||||
@ -172,11 +203,32 @@ void board_autoled_off(int led)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/*****************************************************************************
|
||||||
|
* Name: board_userled_initialize
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* This function should initialize leds for user use, but on RTOS start we
|
||||||
|
* initialize every led for use by RTOS and at end, when RTOS is fully
|
||||||
|
* booted up, we give control of these specific leds for user. So that's why
|
||||||
|
* this function is empty.
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
void board_userled_initialize(void)
|
void board_userled_initialize(void)
|
||||||
{
|
{
|
||||||
/* Already initialized by stm32_led_initialize. */
|
/* Already initialized by stm32_led_initialize. */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************
|
||||||
|
* Name: board_userled
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Sets led to ledon state.
|
||||||
|
*
|
||||||
|
* Input parameters:
|
||||||
|
* led - Led to be set, indexed from 0
|
||||||
|
* ledon - new state for the led.
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
void board_userled(int led, bool ledon)
|
void board_userled(int led, bool ledon)
|
||||||
{
|
{
|
||||||
#ifndef CONFIG_ARCH_LEDS
|
#ifndef CONFIG_ARCH_LEDS
|
||||||
@ -186,9 +238,19 @@ void board_userled(int led, bool ledon)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
unsigned int ledbit = 1 << led;
|
unsigned int ledbit = 1 << led;
|
||||||
led_state(ledon, ledbit);
|
led_state(ledon, ledbit);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************
|
||||||
|
* Name: board_userled_all
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Sets whole ledset to given state.
|
||||||
|
*
|
||||||
|
* Input parameters:
|
||||||
|
* ledset - Led bits to be set on or off
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
void board_userled_all(uint8_t ledset)
|
void board_userled_all(uint8_t ledset)
|
||||||
{
|
{
|
||||||
#ifdef CONFIG_ARCH_LEDS
|
#ifdef CONFIG_ARCH_LEDS
|
||||||
@ -199,3 +261,4 @@ void board_userled_all(uint8_t ledset)
|
|||||||
led_state(led_OFF, ~ledset);
|
led_state(led_OFF, ~ledset);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,8 +37,6 @@
|
|||||||
* Included Files
|
* Included Files
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include <debug.h>
|
|
||||||
#include <fcntl.h>
|
|
||||||
#include <nuttx/config.h>
|
#include <nuttx/config.h>
|
||||||
#include <nuttx/mmcsd.h>
|
#include <nuttx/mmcsd.h>
|
||||||
#include <nuttx/spi/spi.h>
|
#include <nuttx/spi/spi.h>
|
||||||
@ -72,15 +70,15 @@ static const int SD_SLOT_NO = 0; /* There is only one SD slot */
|
|||||||
|
|
||||||
/* Media changed callback */
|
/* Media changed callback */
|
||||||
|
|
||||||
static spi_mediachange_t mediachangeclbk;
|
static spi_mediachange_t g_chmediaclbk;
|
||||||
|
|
||||||
/* Argument for media changed callback */
|
/* Argument for media changed callback */
|
||||||
|
|
||||||
static void *mediachangearg;
|
static void *chmediaarg;
|
||||||
|
|
||||||
/* Semafor to inform stm32_cd_thread that card was inserted or pulled out */
|
/* Semafor to inform stm32_cd_thread that card was inserted or pulled out */
|
||||||
|
|
||||||
static sem_t cdsem;
|
static sem_t g_cdsem;
|
||||||
|
|
||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
* Private Functions
|
* Private Functions
|
||||||
@ -90,8 +88,8 @@ static sem_t cdsem;
|
|||||||
* Name: stm32_cd_thread
|
* Name: stm32_cd_thread
|
||||||
*
|
*
|
||||||
* Description:
|
* Description:
|
||||||
* Working thread to call mediachanged function when card is inserted or
|
* Working thread to call mediachanged function when card is inserted or
|
||||||
* pulled out.
|
* pulled out.
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
static void *stm32_cd_thread(void *arg)
|
static void *stm32_cd_thread(void *arg)
|
||||||
@ -100,16 +98,16 @@ static void *stm32_cd_thread(void *arg)
|
|||||||
|
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
sem_wait(&cdsem);
|
sem_wait(&g_cdsem);
|
||||||
|
|
||||||
if (mediachangeclbk)
|
if (g_chmediaclbk)
|
||||||
{
|
{
|
||||||
/* Card doesn't seem to initialize properly without letting it to
|
/* Card doesn't seem to initialize properly without letting it to
|
||||||
* rest for a millsecond or so.
|
* rest for a millsecond or so.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
usleep(1 * 1000);
|
usleep(1 * 1000);
|
||||||
mediachangeclbk(mediachangearg);
|
g_chmediaclbk(chmediaarg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -120,7 +118,7 @@ static void *stm32_cd_thread(void *arg)
|
|||||||
* Name: stm32_cd
|
* Name: stm32_cd
|
||||||
*
|
*
|
||||||
* Description:
|
* Description:
|
||||||
* Card detect interrupt handler.
|
* Card detect interrupt handler.
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
static int stm32_cd(int irq, FAR void *context)
|
static int stm32_cd(int irq, FAR void *context)
|
||||||
@ -128,8 +126,8 @@ static int stm32_cd(int irq, FAR void *context)
|
|||||||
static const int debounce_time = 100; /* [ms] */
|
static const int debounce_time = 100; /* [ms] */
|
||||||
static uint32_t now = 0;
|
static uint32_t now = 0;
|
||||||
static uint32_t prev = 0;
|
static uint32_t prev = 0;
|
||||||
|
|
||||||
struct timespec tp;
|
struct timespec tp;
|
||||||
|
|
||||||
clock_gettime(CLOCK_MONOTONIC, &tp);
|
clock_gettime(CLOCK_MONOTONIC, &tp);
|
||||||
now = tp.tv_sec * 1000 + tp.tv_nsec / 1000000;
|
now = tp.tv_sec * 1000 + tp.tv_nsec / 1000000;
|
||||||
|
|
||||||
@ -141,7 +139,7 @@ static int stm32_cd(int irq, FAR void *context)
|
|||||||
if (now - debounce_time > prev)
|
if (now - debounce_time > prev)
|
||||||
{
|
{
|
||||||
prev = now;
|
prev = now;
|
||||||
sem_post(&cdsem);
|
sem_post(&g_cdsem);
|
||||||
}
|
}
|
||||||
|
|
||||||
return OK;
|
return OK;
|
||||||
@ -155,31 +153,32 @@ static int stm32_cd(int irq, FAR void *context)
|
|||||||
* Name: stm32_spi1register
|
* Name: stm32_spi1register
|
||||||
*
|
*
|
||||||
* Description:
|
* Description:
|
||||||
* Registers media change callback
|
* Registers media change callback
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
int stm32_spi1register(FAR struct spi_dev_s *dev, spi_mediachange_t callback,
|
int stm32_spi1register(FAR struct spi_dev_s *dev, spi_mediachange_t callback,
|
||||||
FAR void *arg)
|
FAR void *arg)
|
||||||
{
|
{
|
||||||
mediachangeclbk = callback;
|
g_chmediaclbk = callback;
|
||||||
mediachangearg = arg;
|
chmediaarg = arg;
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
* Name: stm32_sdinitialize
|
* Name: stm32_mmcsd_initialize
|
||||||
*
|
*
|
||||||
* Description:
|
* Description:
|
||||||
* Initialize SPI-based SD card and card detect thread.
|
* Initialize SPI-based SD card and card detect thread.
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
int stm32_sdinitialize(int minor)
|
int stm32_mmcsd_initialize(int minor)
|
||||||
{
|
{
|
||||||
FAR struct spi_dev_s *spi;
|
FAR struct spi_dev_s *spi;
|
||||||
|
struct sched_param schparam;
|
||||||
|
pthread_attr_t pattr;
|
||||||
int rv;
|
int rv;
|
||||||
|
|
||||||
spi = stm32_spibus_initialize(SD_SPI_PORT);
|
if ((spi = stm32_spibus_initialize(SD_SPI_PORT)) == NULL)
|
||||||
if (!spi)
|
|
||||||
{
|
{
|
||||||
ferr("failed to initialize SPI port %d\n", SD_SPI_PORT);
|
ferr("failed to initialize SPI port %d\n", SD_SPI_PORT);
|
||||||
return -ENODEV;
|
return -ENODEV;
|
||||||
@ -193,15 +192,18 @@ int stm32_sdinitialize(int minor)
|
|||||||
}
|
}
|
||||||
|
|
||||||
stm32_gpiosetevent(GPIO_SD_CD, true, true, true, stm32_cd);
|
stm32_gpiosetevent(GPIO_SD_CD, true, true, true, stm32_cd);
|
||||||
sem_init(&cdsem, 0, 0);
|
|
||||||
|
|
||||||
pthread_attr_t pattr;
|
sem_init(&g_cdsem, 0, 0);
|
||||||
pthread_attr_init(&pattr);
|
pthread_attr_init(&pattr);
|
||||||
|
|
||||||
#ifdef CONFIG_DEBUG_FS
|
#ifdef CONFIG_DEBUG_FS
|
||||||
pthread_attr_setstacksize(&pattr, 1024);
|
pthread_attr_setstacksize(&pattr, 1024);
|
||||||
#else
|
#else
|
||||||
pthread_attr_setstacksize(&pattr, 256);
|
pthread_attr_setstacksize(&pattr, 256);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
schparam.sched_priority = 50;
|
||||||
|
pthread_attr_setschedparam(&pattr, &schedparam);
|
||||||
pthread_create(NULL, &pattr, stm32_cd_thread, NULL);
|
pthread_create(NULL, &pattr, stm32_cd_thread, NULL);
|
||||||
|
|
||||||
return OK;
|
return OK;
|
||||||
|
@ -36,8 +36,6 @@
|
|||||||
* Included Files
|
* Included Files
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include <debug.h>
|
|
||||||
#include <nuttx/config.h>
|
|
||||||
#include <nuttx/spi/spi.h>
|
#include <nuttx/spi/spi.h>
|
||||||
|
|
||||||
#include "stm32_butterfly2.h"
|
#include "stm32_butterfly2.h"
|
||||||
@ -52,11 +50,11 @@
|
|||||||
* Name: stm32_spidev_initialize
|
* Name: stm32_spidev_initialize
|
||||||
*
|
*
|
||||||
* Description:
|
* Description:
|
||||||
* Called to configure SPI chip select GPIO pins.
|
* Called to configure SPI chip select GPIO pins.
|
||||||
*
|
*
|
||||||
* Note:
|
* Note:
|
||||||
* Here only CS pins are configured as SPI pins are configured by driver
|
* Here only CS pins are configured as SPI pins are configured by driver
|
||||||
* itself.
|
* itself.
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
void stm32_spidev_initialize(void)
|
void stm32_spidev_initialize(void)
|
||||||
@ -69,7 +67,7 @@ void stm32_spidev_initialize(void)
|
|||||||
* Name: stm32_spi1select
|
* Name: stm32_spi1select
|
||||||
*
|
*
|
||||||
* Description:
|
* Description:
|
||||||
* Function asserts given devid based on select
|
* Function asserts given devid based on select
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
void stm32_spi1select(FAR struct spi_dev_s *dev, enum spi_dev_e devid,
|
void stm32_spi1select(FAR struct spi_dev_s *dev, enum spi_dev_e devid,
|
||||||
@ -85,7 +83,7 @@ void stm32_spi1select(FAR struct spi_dev_s *dev, enum spi_dev_e devid,
|
|||||||
* Name: stm32_spi1status
|
* Name: stm32_spi1status
|
||||||
*
|
*
|
||||||
* Description:
|
* Description:
|
||||||
* Return status of devid
|
* Return status of devid
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
uint8_t stm32_spi1status(FAR struct spi_dev_s *dev, enum spi_dev_e devid)
|
uint8_t stm32_spi1status(FAR struct spi_dev_s *dev, enum spi_dev_e devid)
|
||||||
|
@ -37,8 +37,7 @@
|
|||||||
* Include Files
|
* Include Files
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include <stm32_gpio.h>
|
#include "stm32_gpio.h"
|
||||||
#include <stm32_otgfs.h>
|
|
||||||
|
|
||||||
#include "stm32_butterfly2.h"
|
#include "stm32_butterfly2.h"
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
* configs/stm32butterfly2/src/stm32_usb.c
|
* configs/stm32butterfly2/src/stm32_usbhost.c
|
||||||
*
|
*
|
||||||
* Copyright (C) 2016 Michał Łyszczek. All rights reserved.
|
* Copyright (C) 2016 Michał Łyszczek. All rights reserved.
|
||||||
* Author: Michał Łyszczek <michal.lyszczek@gmail.com>
|
* Author: Michał Łyszczek <michal.lyszczek@gmail.com>
|
||||||
@ -37,8 +37,6 @@
|
|||||||
* Include Files
|
* Include Files
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include <assert.h>
|
|
||||||
#include <debug.h>
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <nuttx/config.h>
|
#include <nuttx/config.h>
|
||||||
#include <nuttx/usb/usbhost.h>
|
#include <nuttx/usb/usbhost.h>
|
||||||
@ -79,7 +77,6 @@ static struct usbhost_connection_s *g_usbconn;
|
|||||||
static void* usbhost_detect(void *arg)
|
static void* usbhost_detect(void *arg)
|
||||||
{
|
{
|
||||||
(void)arg;
|
(void)arg;
|
||||||
|
|
||||||
struct usbhost_hubport_s *hport;
|
struct usbhost_hubport_s *hport;
|
||||||
|
|
||||||
for (;;)
|
for (;;)
|
||||||
@ -176,8 +173,6 @@ int stm32_usbhost_initialize(void)
|
|||||||
|
|
||||||
void stm32_usbhost_vbusdrive(int iface, bool enable)
|
void stm32_usbhost_vbusdrive(int iface, bool enable)
|
||||||
{
|
{
|
||||||
DEBUGASSERT(iface == 0);
|
|
||||||
|
|
||||||
stm32_gpiowrite(GPIO_OTGFS_PWRON, enable);
|
stm32_gpiowrite(GPIO_OTGFS_PWRON, enable);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user