Example #1
0
void HAL_SPI_SS_Handler(void *data)
{
    HAL_SPI_Interface spi = (HAL_SPI_Interface)data;
    uint8_t state = !HAL_GPIO_Read(spiState[spi].SPI_SS_Pin);
    spiState[spi].SPI_SS_State = state;
    if (state)
    {
        /* Selected */
        if (spiState[spi].SPI_DMA_Configured)
            SPI_Cmd(spiMap[spi].SPI_Peripheral, ENABLE);
    }
    else
    {
        /* Deselected
         * If there is a pending DMA transfer, it needs to be canceled.
         */
        SPI_Cmd(spiMap[spi].SPI_Peripheral, DISABLE);
        if (spiState[spi].SPI_DMA_Configured)
        {
            HAL_SPI_DMA_Transfer_Cancel(spi);
        }
        else
        {
            /* Just in case clear DR */
            while (SPI_I2S_GetFlagStatus(spiMap[spi].SPI_Peripheral, SPI_I2S_FLAG_RXNE) == SET)
            {
                (void)SPI_I2S_ReceiveData(spiMap[spi].SPI_Peripheral);
            }
        }
    }

    if (spiState[spi].SPI_Select_UserCallback)
        spiState[spi].SPI_Select_UserCallback(state);
}
/*
 * @brief Reads the value of a GPIO pin. Should return either 1 (HIGH) or 0 (LOW).
 */
int32_t digitalRead(pin_t pin)
{
    PinMode mode = HAL_Get_Pin_Mode(pin);
    if (is_af_output_mode(mode))
        return LOW;

    // Safety check
    if( !pinAvailable(pin) ) {
      return LOW;
    }

    return HAL_GPIO_Read(pin);
}
Example #3
0
/**
 * @brief  Returns the selected Button non-filtered state.
 * @param  Button: Specifies the Button to be checked.
 *   This parameter can be one of following parameters:
 *     @arg BUTTON1: Button1
 * @retval Actual Button Pressed state.
 */
uint8_t BUTTON_GetState(Button_TypeDef Button) {
    return HAL_GPIO_Read(HAL_Buttons[Button].pin);
}