add initial Setup
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
commit
bdb5db2009
1955 files changed
+1004711
No files matched your search
@@ -0,0 +1,587 @@
|
||||
|
||||
#ifndef STM32F7XX_HAL_H_
|
||||
#define STM32F7XX_HAL_H_ STM32F7XX_HAL_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#define __IO volatile
|
||||
|
||||
/** @defgroup GPIO_pins_define GPIO pins define
|
||||
* @{
|
||||
*/
|
||||
#define GPIO_PIN_0 ((uint16_t)0x0001U) /* Pin 0 selected */
|
||||
#define GPIO_PIN_1 ((uint16_t)0x0002U) /* Pin 1 selected */
|
||||
#define GPIO_PIN_2 ((uint16_t)0x0004U) /* Pin 2 selected */
|
||||
#define GPIO_PIN_3 ((uint16_t)0x0008U) /* Pin 3 selected */
|
||||
#define GPIO_PIN_4 ((uint16_t)0x0010U) /* Pin 4 selected */
|
||||
#define GPIO_PIN_5 ((uint16_t)0x0020U) /* Pin 5 selected */
|
||||
#define GPIO_PIN_6 ((uint16_t)0x0040U) /* Pin 6 selected */
|
||||
#define GPIO_PIN_7 ((uint16_t)0x0080U) /* Pin 7 selected */
|
||||
#define GPIO_PIN_8 ((uint16_t)0x0100U) /* Pin 8 selected */
|
||||
#define GPIO_PIN_9 ((uint16_t)0x0200U) /* Pin 9 selected */
|
||||
#define GPIO_PIN_10 ((uint16_t)0x0400U) /* Pin 10 selected */
|
||||
#define GPIO_PIN_11 ((uint16_t)0x0800U) /* Pin 11 selected */
|
||||
#define GPIO_PIN_12 ((uint16_t)0x1000U) /* Pin 12 selected */
|
||||
#define GPIO_PIN_13 ((uint16_t)0x2000U) /* Pin 13 selected */
|
||||
#define GPIO_PIN_14 ((uint16_t)0x4000U) /* Pin 14 selected */
|
||||
#define GPIO_PIN_15 ((uint16_t)0x8000U) /* Pin 15 selected */
|
||||
#define GPIO_PIN_All ((uint16_t)0xFFFFU) /* All pins selected */
|
||||
|
||||
#define GPIO_PIN_MASK ((uint32_t)0x0000FFFFU) /* PIN mask for assert test */
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup TIM_Channel TIM Channel
|
||||
* @{
|
||||
*/
|
||||
#define TIM_CHANNEL_1 0x00000000U /*!< Capture/compare channel 1 identifier */
|
||||
#define TIM_CHANNEL_2 0x00000004U /*!< Capture/compare channel 2 identifier */
|
||||
#define TIM_CHANNEL_3 0x00000008U /*!< Capture/compare channel 3 identifier */
|
||||
#define TIM_CHANNEL_4 0x0000000CU /*!< Capture/compare channel 4 identifier */
|
||||
#define TIM_CHANNEL_5 0x00000010U /*!< Compare channel 5 identifier */
|
||||
#define TIM_CHANNEL_6 0x00000014U /*!< Compare channel 6 identifier */
|
||||
#define TIM_CHANNEL_ALL 0x0000003CU /*!< Global Capture/compare channel identifier */
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @brief Set the TIM Autoreload Register value on runtime without calling another time any Init function.
|
||||
* @param __HANDLE__ TIM handle.
|
||||
* @param __AUTORELOAD__ specifies the Counter register new value.
|
||||
* @retval None
|
||||
*/
|
||||
#define __HAL_TIM_SET_AUTORELOAD(__HANDLE__, __AUTORELOAD__) \
|
||||
do{ \
|
||||
(__HANDLE__)->Instance->ARR = (__AUTORELOAD__); \
|
||||
(__HANDLE__)->Init.Period = (__AUTORELOAD__); \
|
||||
} while(0)
|
||||
|
||||
/**
|
||||
* @brief Set the TIM Prescaler on runtime.
|
||||
* @param __HANDLE__ TIM handle.
|
||||
* @param __PRESC__ specifies the Prescaler new value.
|
||||
* @retval None
|
||||
*/
|
||||
#define __HAL_TIM_SET_PRESCALER(__HANDLE__, __PRESC__) ((__HANDLE__)->Instance->PSC = (__PRESC__))
|
||||
|
||||
#define __HAL_TIM_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR1|=(1))
|
||||
|
||||
/**
|
||||
* @brief HAL Status structures definition
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
HAL_OK = 0x00U,
|
||||
HAL_ERROR = 0x01U,
|
||||
HAL_BUSY = 0x02U,
|
||||
HAL_TIMEOUT = 0x03U
|
||||
} HAL_StatusTypeDef;
|
||||
|
||||
/**
|
||||
* @brief HAL Lock structures definition
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
HAL_UNLOCKED = 0x00U,
|
||||
HAL_LOCKED = 0x01U
|
||||
} HAL_LockTypeDef;
|
||||
|
||||
/**
|
||||
* @brief GPIO Bit SET and Bit RESET enumeration
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
GPIO_PIN_RESET = 0,
|
||||
GPIO_PIN_SET
|
||||
} GPIO_PinState;
|
||||
|
||||
/**
|
||||
* @brief HAL Active channel structures definition
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
HAL_TIM_ACTIVE_CHANNEL_1 = 0x01U, /*!< The active channel is 1 */
|
||||
HAL_TIM_ACTIVE_CHANNEL_2 = 0x02U, /*!< The active channel is 2 */
|
||||
HAL_TIM_ACTIVE_CHANNEL_3 = 0x04U, /*!< The active channel is 3 */
|
||||
HAL_TIM_ACTIVE_CHANNEL_4 = 0x08U, /*!< The active channel is 4 */
|
||||
HAL_TIM_ACTIVE_CHANNEL_5 = 0x10U, /*!< The active channel is 5 */
|
||||
HAL_TIM_ACTIVE_CHANNEL_6 = 0x20U, /*!< The active channel is 6 */
|
||||
HAL_TIM_ACTIVE_CHANNEL_CLEARED = 0x00U /*!< All active channels cleared */
|
||||
} HAL_TIM_ActiveChannel;
|
||||
|
||||
/**
|
||||
* @brief HAL State structures definition
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
HAL_TIM_STATE_RESET = 0x00U, /*!< Peripheral not yet initialized or disabled */
|
||||
HAL_TIM_STATE_READY = 0x01U, /*!< Peripheral Initialized and ready for use */
|
||||
HAL_TIM_STATE_BUSY = 0x02U, /*!< An internal process is ongoing */
|
||||
HAL_TIM_STATE_TIMEOUT = 0x03U, /*!< Timeout state */
|
||||
HAL_TIM_STATE_ERROR = 0x04U /*!< Reception process is ongoing */
|
||||
} HAL_TIM_StateTypeDef;
|
||||
|
||||
/**
|
||||
* @brief TIM Channel States definition
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
HAL_TIM_CHANNEL_STATE_RESET = 0x00U, /*!< TIM Channel initial state */
|
||||
HAL_TIM_CHANNEL_STATE_READY = 0x01U, /*!< TIM Channel ready for use */
|
||||
HAL_TIM_CHANNEL_STATE_BUSY = 0x02U, /*!< An internal process is ongoing on the TIM channel */
|
||||
} HAL_TIM_ChannelStateTypeDef;
|
||||
|
||||
|
||||
/** @defgroup TIM_Counter_Mode TIM Counter Mode
|
||||
* @{
|
||||
*/
|
||||
#define TIM_COUNTERMODE_UP 0x00000000U /*!< Counter used as up-counter */
|
||||
#define TIM_COUNTERMODE_DOWN 0x00000001U /*!< Counter used as down-counter */
|
||||
#define TIM_COUNTERMODE_CENTERALIGNED1 0x00000002U /*!< Center-aligned mode 1 */
|
||||
#define TIM_COUNTERMODE_CENTERALIGNED2 0x00000004U /*!< Center-aligned mode 2 */
|
||||
#define TIM_COUNTERMODE_CENTERALIGNED3 0x00000008U /*!< Center-aligned mode 3 */
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup TIM_ClockDivision TIM Clock Division
|
||||
* @{
|
||||
*/
|
||||
#define TIM_CLOCKDIVISION_DIV1 0x00000000U /*!< Clock division: tDTS=tCK_INT */
|
||||
#define TIM_CLOCKDIVISION_DIV2 0x00000001U /*!< Clock division: tDTS=2*tCK_INT */
|
||||
#define TIM_CLOCKDIVISION_DIV4 0x00000002U /*!< Clock division: tDTS=4*tCK_INT */
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup TIM_AutoReloadPreload TIM Auto-Reload Preload
|
||||
* @{
|
||||
*/
|
||||
#define TIM_AUTORELOAD_PRELOAD_DISABLE 0x00000000U /*!< TIMx_ARR register is not buffered */
|
||||
#define TIM_AUTORELOAD_PRELOAD_ENABLE 0x00000001U /*!< TIMx_ARR register is buffered */
|
||||
|
||||
|
||||
/**
|
||||
* @brief TIM Output Compare Configuration Structure definition
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint32_t OCMode; /*!< Specifies the TIM mode.
|
||||
This parameter can be a value of @ref TIM_Output_Compare_and_PWM_modes */
|
||||
|
||||
uint32_t Pulse; /*!< Specifies the pulse value to be loaded into the Capture Compare Register.
|
||||
This parameter can be a number between Min_Data = 0x0000 and Max_Data = 0xFFFF */
|
||||
|
||||
uint32_t OCPolarity; /*!< Specifies the output polarity.
|
||||
This parameter can be a value of @ref TIM_Output_Compare_Polarity */
|
||||
|
||||
uint32_t OCNPolarity; /*!< Specifies the complementary output polarity.
|
||||
This parameter can be a value of @ref TIM_Output_Compare_N_Polarity
|
||||
@note This parameter is valid only for timer instances supporting break feature. */
|
||||
|
||||
uint32_t OCFastMode; /*!< Specifies the Fast mode state.
|
||||
This parameter can be a value of @ref TIM_Output_Fast_State
|
||||
@note This parameter is valid only in PWM1 and PWM2 mode. */
|
||||
|
||||
|
||||
uint32_t OCIdleState; /*!< Specifies the TIM Output Compare pin state during Idle state.
|
||||
This parameter can be a value of @ref TIM_Output_Compare_Idle_State
|
||||
@note This parameter is valid only for timer instances supporting break feature. */
|
||||
|
||||
uint32_t OCNIdleState; /*!< Specifies the TIM Output Compare pin state during Idle state.
|
||||
This parameter can be a value of @ref TIM_Output_Compare_N_Idle_State
|
||||
@note This parameter is valid only for timer instances supporting break feature. */
|
||||
} TIM_OC_InitTypeDef;
|
||||
|
||||
/**
|
||||
* @brief Serial Peripheral Interface
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
__IO uint32_t CR1; /*!< SPI control register 1 (not used in I2S mode), Address offset: 0x00 */
|
||||
__IO uint32_t CR2; /*!< SPI control register 2, Address offset: 0x04 */
|
||||
__IO uint32_t SR; /*!< SPI status register, Address offset: 0x08 */
|
||||
__IO uint32_t DR; /*!< SPI data register, Address offset: 0x0C */
|
||||
__IO uint32_t CRCPR; /*!< SPI CRC polynomial register (not used in I2S mode), Address offset: 0x10 */
|
||||
__IO uint32_t RXCRCR; /*!< SPI RX CRC register (not used in I2S mode), Address offset: 0x14 */
|
||||
__IO uint32_t TXCRCR; /*!< SPI TX CRC register (not used in I2S mode), Address offset: 0x18 */
|
||||
__IO uint32_t I2SCFGR; /*!< SPI_I2S configuration register, Address offset: 0x1C */
|
||||
__IO uint32_t I2SPR; /*!< SPI_I2S prescaler register, Address offset: 0x20 */
|
||||
} SPI_TypeDef;
|
||||
|
||||
|
||||
/**
|
||||
* @brief General Purpose I/O
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
__IO uint32_t MODER; /*!< GPIO port mode register, Address offset: 0x00 */
|
||||
__IO uint32_t OTYPER; /*!< GPIO port output type register, Address offset: 0x04 */
|
||||
__IO uint32_t OSPEEDR; /*!< GPIO port output speed register, Address offset: 0x08 */
|
||||
__IO uint32_t PUPDR; /*!< GPIO port pull-up/pull-down register, Address offset: 0x0C */
|
||||
__IO uint32_t IDR; /*!< GPIO port input data register, Address offset: 0x10 */
|
||||
__IO uint32_t ODR; /*!< GPIO port output data register, Address offset: 0x14 */
|
||||
__IO uint32_t BSRR; /*!< GPIO port bit set/reset register, Address offset: 0x18 */
|
||||
__IO uint32_t LCKR; /*!< GPIO port configuration lock register, Address offset: 0x1C */
|
||||
__IO uint32_t AFR[2]; /*!< GPIO alternate function registers, Address offset: 0x20-0x24 */
|
||||
} GPIO_TypeDef;
|
||||
|
||||
|
||||
/** @defgroup TIM_Output_Compare_and_PWM_modes TIM Output Compare and PWM Modes
|
||||
* @{
|
||||
*/
|
||||
#define TIM_OCMODE_TIMING 0x00000000U /*!< Frozen */
|
||||
#define TIM_OCMODE_ACTIVE 0x00000001U /*!< Set channel to active level on match */
|
||||
#define TIM_OCMODE_INACTIVE 0x00000002U /*!< Set channel to inactive level on match */
|
||||
#define TIM_OCMODE_TOGGLE 0x00000003U /*!< Toggle */
|
||||
#define TIM_OCMODE_PWM1 0x00000004U /*!< PWM mode 1 */
|
||||
#define TIM_OCMODE_PWM2 0x00000005U /*!< PWM mode 2 */
|
||||
#define TIM_OCMODE_FORCED_ACTIVE 0x00000006U /*!< Force active level */
|
||||
#define TIM_OCMODE_FORCED_INACTIVE 0x00000007U /*!< Force inactive level */
|
||||
#define TIM_OCMODE_RETRIGERRABLE_OPM1 0x00000008U /*!< Retrigerrable OPM mode 1 */
|
||||
#define TIM_OCMODE_RETRIGERRABLE_OPM2 0x00000009U /*!< Retrigerrable OPM mode 2 */
|
||||
#define TIM_OCMODE_COMBINED_PWM1 0x0000000AU /*!< Combined PWM mode 1 */
|
||||
#define TIM_OCMODE_COMBINED_PWM2 0x0000000BU /*!< Combined PWM mode 2 */
|
||||
#define TIM_OCMODE_ASYMMETRIC_PWM1 0x0000000CU /*!< Asymmetric PWM mode 1 */
|
||||
#define TIM_OCMODE_ASYMMETRIC_PWM2 0x0000000DU /*!< Asymmetric PWM mode 2 */
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup TIM_Event_Source TIM Event Source
|
||||
* @{
|
||||
*/
|
||||
#define TIM_EVENTSOURCE_UPDATE 0x00000000U /*!< Reinitialize the counter and generates an update of the registers */
|
||||
#define TIM_EVENTSOURCE_CC1 0x00000001U /*!< A capture/compare event is generated on channel 1 */
|
||||
#define TIM_EVENTSOURCE_CC2 0x00000002U /*!< A capture/compare event is generated on channel 2 */
|
||||
#define TIM_EVENTSOURCE_CC3 0x00000003U /*!< A capture/compare event is generated on channel 3 */
|
||||
#define TIM_EVENTSOURCE_CC4 0x00000004U /*!< A capture/compare event is generated on channel 4 */
|
||||
#define TIM_EVENTSOURCE_COM 0x00000005U /*!< A commutation event is generated */
|
||||
#define TIM_EVENTSOURCE_TRIGGER 0x00000006U /*!< A trigger event is generated */
|
||||
#define TIM_EVENTSOURCE_BREAK 0x00000007U /*!< A break event is generated */
|
||||
#define TIM_EVENTSOURCE_BREAK2 0x00000008U /*!< A break 2 event is generated */
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup TIM_Output_Fast_State TIM Output Fast State
|
||||
* @{
|
||||
*/
|
||||
#define TIM_OCFAST_DISABLE 0x00000000U /*!< Output Compare fast disable */
|
||||
#define TIM_OCFAST_ENABLE 0x00000001U /*!< Output Compare fast enable */
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup TIM_Output_Compare_N_State TIM Complementary Output Compare State
|
||||
* @{
|
||||
*/
|
||||
#define TIM_OUTPUTNSTATE_DISABLE 0x00000000U /*!< OCxN is disabled */
|
||||
#define TIM_OUTPUTNSTATE_ENABLE 0x00000001U /*!< OCxN is enabled */
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup TIM_Output_Compare_Polarity TIM Output Compare Polarity
|
||||
* @{
|
||||
*/
|
||||
#define TIM_OCPOLARITY_HIGH 0x00000000U /*!< Capture/Compare output polarity */
|
||||
#define TIM_OCPOLARITY_LOW 0x00000001U /*!< Capture/Compare output polarity */
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup TIM_Output_Compare_N_Polarity TIM Complementary Output Compare Polarity
|
||||
* @{
|
||||
*/
|
||||
#define TIM_OCNPOLARITY_HIGH 0x00000000U /*!< Capture/Compare complementary output polarity */
|
||||
#define TIM_OCNPOLARITY_LOW 0x00000001U /*!< Capture/Compare complementary output polarity */
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief TIM
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
__IO uint32_t CR1; /*!< TIM control register 1, Address offset: 0x00 */
|
||||
__IO uint32_t CR2; /*!< TIM control register 2, Address offset: 0x04 */
|
||||
__IO uint32_t SMCR; /*!< TIM slave mode control register, Address offset: 0x08 */
|
||||
__IO uint32_t DIER; /*!< TIM DMA/interrupt enable register, Address offset: 0x0C */
|
||||
__IO uint32_t SR; /*!< TIM status register, Address offset: 0x10 */
|
||||
__IO uint32_t EGR; /*!< TIM event generation register, Address offset: 0x14 */
|
||||
__IO uint32_t CCMR1; /*!< TIM capture/compare mode register 1, Address offset: 0x18 */
|
||||
__IO uint32_t CCMR2; /*!< TIM capture/compare mode register 2, Address offset: 0x1C */
|
||||
__IO uint32_t CCER; /*!< TIM capture/compare enable register, Address offset: 0x20 */
|
||||
__IO uint32_t CNT; /*!< TIM counter register, Address offset: 0x24 */
|
||||
__IO uint32_t PSC; /*!< TIM prescaler, Address offset: 0x28 */
|
||||
__IO uint32_t ARR; /*!< TIM auto-reload register, Address offset: 0x2C */
|
||||
__IO uint32_t RCR; /*!< TIM repetition counter register, Address offset: 0x30 */
|
||||
__IO uint32_t CCR1; /*!< TIM capture/compare register 1, Address offset: 0x34 */
|
||||
__IO uint32_t CCR2; /*!< TIM capture/compare register 2, Address offset: 0x38 */
|
||||
__IO uint32_t CCR3; /*!< TIM capture/compare register 3, Address offset: 0x3C */
|
||||
__IO uint32_t CCR4; /*!< TIM capture/compare register 4, Address offset: 0x40 */
|
||||
__IO uint32_t BDTR; /*!< TIM break and dead-time register, Address offset: 0x44 */
|
||||
__IO uint32_t DCR; /*!< TIM DMA control register, Address offset: 0x48 */
|
||||
__IO uint32_t DMAR; /*!< TIM DMA address for full transfer, Address offset: 0x4C */
|
||||
__IO uint32_t OR; /*!< TIM option register, Address offset: 0x50 */
|
||||
__IO uint32_t CCMR3; /*!< TIM capture/compare mode register 3, Address offset: 0x54 */
|
||||
__IO uint32_t CCR5; /*!< TIM capture/compare mode register5, Address offset: 0x58 */
|
||||
__IO uint32_t CCR6; /*!< TIM capture/compare mode register6, Address offset: 0x5C */
|
||||
} TIM_TypeDef;
|
||||
|
||||
/**
|
||||
* @brief HAL SPI State structure definition
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
HAL_SPI_STATE_RESET = 0x00U, /*!< Peripheral not Initialized */
|
||||
HAL_SPI_STATE_READY = 0x01U, /*!< Peripheral Initialized and ready for use */
|
||||
HAL_SPI_STATE_BUSY = 0x02U, /*!< an internal process is ongoing */
|
||||
HAL_SPI_STATE_BUSY_TX = 0x03U, /*!< Data Transmission process is ongoing */
|
||||
HAL_SPI_STATE_BUSY_RX = 0x04U, /*!< Data Reception process is ongoing */
|
||||
HAL_SPI_STATE_BUSY_TX_RX = 0x05U, /*!< Data Transmission and Reception process is ongoing */
|
||||
HAL_SPI_STATE_ERROR = 0x06U, /*!< SPI error state */
|
||||
HAL_SPI_STATE_ABORT = 0x07U /*!< SPI abort is ongoing */
|
||||
} HAL_SPI_StateTypeDef;
|
||||
|
||||
/**
|
||||
* @brief DMA handle Structure definition
|
||||
*/
|
||||
typedef struct __DMA_HandleTypeDef
|
||||
{
|
||||
void* Instance;
|
||||
}DMA_HandleTypeDef;
|
||||
|
||||
/**
|
||||
* @brief SPI Configuration Structure definition
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint32_t Mode; /*!< Specifies the SPI operating mode.
|
||||
This parameter can be a value of @ref SPI_Mode */
|
||||
|
||||
uint32_t Direction; /*!< Specifies the SPI bidirectional mode state.
|
||||
This parameter can be a value of @ref SPI_Direction */
|
||||
|
||||
uint32_t DataSize; /*!< Specifies the SPI data size.
|
||||
This parameter can be a value of @ref SPI_Data_Size */
|
||||
|
||||
uint32_t CLKPolarity; /*!< Specifies the serial clock steady state.
|
||||
This parameter can be a value of @ref SPI_Clock_Polarity */
|
||||
|
||||
uint32_t CLKPhase; /*!< Specifies the clock active edge for the bit capture.
|
||||
This parameter can be a value of @ref SPI_Clock_Phase */
|
||||
|
||||
uint32_t NSS; /*!< Specifies whether the NSS signal is managed by
|
||||
hardware (NSS pin) or by software using the SSI bit.
|
||||
This parameter can be a value of @ref SPI_Slave_Select_management */
|
||||
|
||||
uint32_t BaudRatePrescaler; /*!< Specifies the Baud Rate prescaler value which will be
|
||||
used to configure the transmit and receive SCK clock.
|
||||
This parameter can be a value of @ref SPI_BaudRate_Prescaler
|
||||
@note The communication clock is derived from the master
|
||||
clock. The slave clock does not need to be set. */
|
||||
|
||||
uint32_t FirstBit; /*!< Specifies whether data transfers start from MSB or LSB bit.
|
||||
This parameter can be a value of @ref SPI_MSB_LSB_transmission */
|
||||
|
||||
uint32_t TIMode; /*!< Specifies if the TI mode is enabled or not.
|
||||
This parameter can be a value of @ref SPI_TI_mode */
|
||||
|
||||
uint32_t CRCCalculation; /*!< Specifies if the CRC calculation is enabled or not.
|
||||
This parameter can be a value of @ref SPI_CRC_Calculation */
|
||||
|
||||
uint32_t CRCPolynomial; /*!< Specifies the polynomial used for the CRC calculation.
|
||||
This parameter must be an odd number between Min_Data = 1 and Max_Data = 65535 */
|
||||
|
||||
uint32_t CRCLength; /*!< Specifies the CRC Length used for the CRC calculation.
|
||||
CRC Length is only used with Data8 and Data16, not other data size
|
||||
This parameter can be a value of @ref SPI_CRC_length */
|
||||
|
||||
uint32_t NSSPMode; /*!< Specifies whether the NSSP signal is enabled or not .
|
||||
This parameter can be a value of @ref SPI_NSSP_Mode
|
||||
This mode is activated by the NSSP bit in the SPIx_CR2 register and
|
||||
it takes effect only if the SPI interface is configured as Motorola SPI
|
||||
master (FRF=0) with capture on the first edge (SPIx_CR1 CPHA = 0,
|
||||
CPOL setting is ignored).. */
|
||||
} SPI_InitTypeDef;
|
||||
|
||||
/**
|
||||
* @brief TIM Time base Configuration Structure definition
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint32_t Prescaler; /*!< Specifies the prescaler value used to divide the TIM clock.
|
||||
This parameter can be a number between Min_Data = 0x0000 and Max_Data = 0xFFFF */
|
||||
|
||||
uint32_t CounterMode; /*!< Specifies the counter mode.
|
||||
This parameter can be a value of @ref TIM_Counter_Mode */
|
||||
|
||||
uint32_t Period; /*!< Specifies the period value to be loaded into the active
|
||||
Auto-Reload Register at the next update event.
|
||||
This parameter can be a number between Min_Data = 0x0000 and Max_Data = 0xFFFF. */
|
||||
|
||||
uint32_t ClockDivision; /*!< Specifies the clock division.
|
||||
This parameter can be a value of @ref TIM_ClockDivision */
|
||||
|
||||
uint32_t RepetitionCounter; /*!< Specifies the repetition counter value. Each time the RCR downcounter
|
||||
reaches zero, an update event is generated and counting restarts
|
||||
from the RCR value (N).
|
||||
This means in PWM mode that (N+1) corresponds to:
|
||||
- the number of PWM periods in edge-aligned mode
|
||||
- the number of half PWM period in center-aligned mode
|
||||
GP timers: this parameter must be a number between Min_Data = 0x00 and
|
||||
Max_Data = 0xFF.
|
||||
Advanced timers: this parameter must be a number between Min_Data = 0x0000 and
|
||||
Max_Data = 0xFFFF. */
|
||||
|
||||
uint32_t AutoReloadPreload; /*!< Specifies the auto-reload preload.
|
||||
This parameter can be a value of @ref TIM_AutoReloadPreload */
|
||||
} TIM_Base_InitTypeDef;
|
||||
|
||||
/**
|
||||
* @brief SPI handle Structure definition
|
||||
*/
|
||||
typedef struct __SPI_HandleTypeDef
|
||||
{
|
||||
SPI_TypeDef* Instance; /*!< SPI registers base address */
|
||||
|
||||
SPI_InitTypeDef Init; /*!< SPI communication parameters */
|
||||
|
||||
uint8_t* pTxBuffPtr; /*!< Pointer to SPI Tx transfer Buffer */
|
||||
|
||||
uint16_t TxXferSize; /*!< SPI Tx Transfer size */
|
||||
|
||||
__IO uint16_t TxXferCount; /*!< SPI Tx Transfer Counter */
|
||||
|
||||
uint8_t* pRxBuffPtr; /*!< Pointer to SPI Rx transfer Buffer */
|
||||
|
||||
uint16_t RxXferSize; /*!< SPI Rx Transfer size */
|
||||
|
||||
__IO uint16_t RxXferCount; /*!< SPI Rx Transfer Counter */
|
||||
|
||||
uint32_t CRCSize; /*!< SPI CRC size used for the transfer */
|
||||
|
||||
void (*RxISR)(struct __SPI_HandleTypeDef* hspi); /*!< function pointer on Rx ISR */
|
||||
|
||||
void (*TxISR)(struct __SPI_HandleTypeDef* hspi); /*!< function pointer on Tx ISR */
|
||||
|
||||
DMA_HandleTypeDef* hdmatx; /*!< SPI Tx DMA Handle parameters */
|
||||
|
||||
DMA_HandleTypeDef* hdmarx; /*!< SPI Rx DMA Handle parameters */
|
||||
|
||||
HAL_LockTypeDef Lock; /*!< Locking object */
|
||||
|
||||
__IO HAL_SPI_StateTypeDef State; /*!< SPI communication state */
|
||||
|
||||
__IO uint32_t ErrorCode; /*!< SPI Error code */
|
||||
} SPI_HandleTypeDef;
|
||||
|
||||
/**
|
||||
* @brief TIM Time Base Handle Structure definition
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
TIM_TypeDef* Instance; /*!< Register base address */
|
||||
TIM_Base_InitTypeDef Init; /*!< TIM Time Base required parameters */
|
||||
HAL_TIM_ActiveChannel Channel; /*!< Active channel */
|
||||
DMA_HandleTypeDef* hdma[7]; /*!< DMA Handlers array
|
||||
This array is accessed by a @ref DMA_Handle_index */
|
||||
HAL_LockTypeDef Lock; /*!< Locking object */
|
||||
__IO HAL_TIM_StateTypeDef State; /*!< TIM operation state */
|
||||
__IO HAL_TIM_ChannelStateTypeDef ChannelState[6]; /*!< TIM channel operation state */
|
||||
__IO HAL_TIM_ChannelStateTypeDef ChannelNState[4]; /*!< TIM complementary channel operation state */
|
||||
} TIM_HandleTypeDef;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
extern SPI_TypeDef __int_SPI1;
|
||||
extern SPI_TypeDef __int_SPI2;
|
||||
extern SPI_TypeDef __int_SPI3;
|
||||
extern SPI_TypeDef __int_SPI4;
|
||||
extern SPI_TypeDef __int_SPI5;
|
||||
extern SPI_TypeDef __int_SPI6;
|
||||
|
||||
extern TIM_TypeDef __int_TIM1;
|
||||
extern TIM_TypeDef __int_TIM2;
|
||||
extern TIM_TypeDef __int_TIM3;
|
||||
extern TIM_TypeDef __int_TIM4;
|
||||
extern TIM_TypeDef __int_TIM5;
|
||||
extern TIM_TypeDef __int_TIM6;
|
||||
extern TIM_TypeDef __int_TIM7;
|
||||
extern TIM_TypeDef __int_TIM8;
|
||||
extern TIM_TypeDef __int_TIM9;
|
||||
extern TIM_TypeDef __int_TIM10;
|
||||
extern TIM_TypeDef __int_TIM11;
|
||||
extern TIM_TypeDef __int_TIM12;
|
||||
extern TIM_TypeDef __int_TIM13;
|
||||
extern TIM_TypeDef __int_TIM14;
|
||||
|
||||
|
||||
|
||||
/** @addtogroup Peripheral_declaration
|
||||
* @{
|
||||
*/
|
||||
#define TIM2 ((TIM_TypeDef *) &__int_TIM2)
|
||||
#define TIM3 ((TIM_TypeDef *) &__int_TIM3)
|
||||
#define TIM4 ((TIM_TypeDef *) &__int_TIM4)
|
||||
#define TIM5 ((TIM_TypeDef *) &__int_TIM5)
|
||||
#define TIM6 ((TIM_TypeDef *) &__int_TIM6)
|
||||
#define TIM7 ((TIM_TypeDef *) &__int_TIM7)
|
||||
#define TIM12 ((TIM_TypeDef *) &__int_TIM12)
|
||||
#define TIM13 ((TIM_TypeDef *) &__int_TIM13)
|
||||
#define TIM14 ((TIM_TypeDef *) &__int_TIM14)
|
||||
#define SPI2 ((SPI_TypeDef *) &__int_SPI2)
|
||||
#define SPI3 ((SPI_TypeDef *) &__int_SPI3)
|
||||
#define TIM1 ((TIM_TypeDef *) &__int_TIM1)
|
||||
#define TIM8 ((TIM_TypeDef *) &__int_TIM8)
|
||||
#define SPI1 ((SPI_TypeDef *) &__int_SPI1)
|
||||
#define SPI4 ((SPI_TypeDef *) &__int_SPI4)
|
||||
#define TIM9 ((TIM_TypeDef *) &__int_TIM9)
|
||||
#define TIM10 ((TIM_TypeDef *) &__int_TIM10)
|
||||
#define TIM11 ((TIM_TypeDef *) &__int_TIM11)
|
||||
#define SPI5 ((SPI_TypeDef *) &__int_SPI5)
|
||||
#define SPI6 ((SPI_TypeDef *) &__int_SPI6)
|
||||
#define GPIOA ((GPIO_TypeDef *) 0x01)
|
||||
#define GPIOB ((GPIO_TypeDef *) 0x02)
|
||||
#define GPIOC ((GPIO_TypeDef *) 0x03)
|
||||
#define GPIOD ((GPIO_TypeDef *) 0x04)
|
||||
#define GPIOE ((GPIO_TypeDef *) 0x05)
|
||||
#define GPIOF ((GPIO_TypeDef *) 0x06)
|
||||
#define GPIOG ((GPIO_TypeDef *) 0x07)
|
||||
#define GPIOH ((GPIO_TypeDef *) 0x08)
|
||||
#define GPIOI ((GPIO_TypeDef *) 0x09)
|
||||
#define GPIOJ ((GPIO_TypeDef *) 0x0A)
|
||||
#define GPIOK ((GPIO_TypeDef *) 0x0B)
|
||||
|
||||
|
||||
|
||||
GPIO_PinState HAL_GPIO_ReadPin(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
|
||||
void HAL_GPIO_WritePin(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, GPIO_PinState PinState);
|
||||
void HAL_GPIO_TogglePin(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
|
||||
|
||||
HAL_StatusTypeDef HAL_SPI_TransmitReceive(SPI_HandleTypeDef* hspi, uint8_t* pTxData, uint8_t* pRxData, uint16_t Size,
|
||||
uint32_t Timeout);
|
||||
|
||||
HAL_StatusTypeDef HAL_TIM_OnePulse_Start_IT(TIM_HandleTypeDef* htim, uint32_t OutputChannel);
|
||||
HAL_StatusTypeDef HAL_TIM_OnePulse_Stop_IT(TIM_HandleTypeDef* htim, uint32_t OutputChannel);
|
||||
HAL_StatusTypeDef HAL_TIM_GenerateEvent(TIM_HandleTypeDef* htim, uint32_t EventSource);
|
||||
HAL_StatusTypeDef HAL_TIM_OnePulse_Stop(TIM_HandleTypeDef* htim, uint32_t OutputChannel);
|
||||
HAL_StatusTypeDef HAL_TIM_PWM_Start(TIM_HandleTypeDef* htim, uint32_t Channel);
|
||||
HAL_StatusTypeDef HAL_TIM_PWM_Stop(TIM_HandleTypeDef* htim, uint32_t Channel);
|
||||
HAL_StatusTypeDef HAL_TIM_PWM_ConfigChannel(TIM_HandleTypeDef* htim, const TIM_OC_InitTypeDef* sConfig, uint32_t Channel);
|
||||
HAL_StatusTypeDef HAL_TIM_Base_Init(TIM_HandleTypeDef* htim);
|
||||
|
||||
#endif /* STM32F7XX_HAL_H_ */
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,745 @@
|
||||
#include "stm32f7xx_hal.h"
|
||||
#include "main.h"
|
||||
#include <Windows.h>
|
||||
#include <stdint.h>
|
||||
|
||||
// USE THIS DEFINE TO DISABLE THE GATING SIMULATION AND INSTEAD USE
|
||||
// THE PWM IRQS OF THE PWM GENERATOR DIRECTLY!!!
|
||||
//#define USE_PWM_GENERATOR_DIRECTLY_INSTEAD_OF_GATING_SLAVE
|
||||
|
||||
#define STATUS_HIGHZ_MASK ( 1 << 0 )
|
||||
#define STATUS_DIRECTION_MASK ( 1 << 4 )
|
||||
#define STATUS_NOTPERF_CMD_MASK ( 1 << 7 )
|
||||
#define STATUS_WRONG_CMD_MASK ( 1 << 8 )
|
||||
#define STATUS_UNDERVOLT_MASK ( 1 << 9 )
|
||||
#define STATUS_THR_WARN_MASK ( 1 << 10 )
|
||||
#define STATUS_THR_SHORTD_MASK ( 1 << 11 )
|
||||
#define STATUS_OCD_MASK ( 1 << 12 )
|
||||
|
||||
#define STEP_REG_RANGE_MASK 0x1F
|
||||
#define STEP_REG_CMD_MASK 0xE0
|
||||
|
||||
#define STEP_CMD_NOP_PREFIX 0x00 //Nothing
|
||||
#define STEP_CMD_NOP_LENGTH 0x01
|
||||
#define STEP_CMD_SET_PREFIX 0x00 //Writes VALUE in PARAM register
|
||||
#define STEP_CMD_SET_LENGTH 0x01
|
||||
#define STEP_CMD_SET_MAX_PAYLOAD 0x04
|
||||
#define STEP_CMD_GET_PREFIX 0x20 //Reads VALUE from PARAM register
|
||||
#define STEP_CMD_GET_LENGTH 0x01
|
||||
#define STEP_CMD_GET_MAX_PAYLOAD 0x04
|
||||
#define STEP_CMD_ENA_PREFIX 0xB8 //Enable the power stage
|
||||
#define STEP_CMD_ENA_LENGTH 0x01
|
||||
#define STEP_CMD_DIS_PREFIX 0xA8 //Puts the bridges in High Impedance status immediately
|
||||
#define STEP_CMD_DIS_LENGTH 0x01
|
||||
#define STEP_CMD_STA_PREFIX 0xD0 //Returns the status register value
|
||||
#define STEP_CMD_STA_LENGTH 0x03
|
||||
#define STEP_REG_ABS_POS 0x01
|
||||
#define STEP_LEN_ABS_POS 0x03
|
||||
#define STEP_MASK_ABS_POS 0x3FFFFF
|
||||
#define STEP_OFFSET_ABS_POS 0x0
|
||||
|
||||
#define STEP_REG_EL_POS 0x02
|
||||
#define STEP_LEN_EL_POS 0x02
|
||||
#define STEP_MASK_EL_POS 0x1FF
|
||||
#define STEP_OFFSET_EL_POS 0x0
|
||||
|
||||
#define STEP_REG_MARK 0x03
|
||||
#define STEP_LEN_MARK 0x03
|
||||
#define STEP_MASK_MARK 0x3FFFFF
|
||||
#define STEP_OFFSET_MARK 0x0
|
||||
|
||||
#define STEP_REG_TVAL 0x09
|
||||
#define STEP_LEN_TVAL 0x01
|
||||
#define STEP_MASK_TVAL 0x7F
|
||||
#define STEP_OFFSET_TVAL 0x0
|
||||
|
||||
#define STEP_REG_T_FAST 0x0E
|
||||
#define STEP_LEN_T_FAST 0x01
|
||||
#define STEP_MASK_T_FAST 0xFF
|
||||
#define STEP_OFFSET_T_FAST 0x0
|
||||
|
||||
#define STEP_REG_TON_MIN 0x0F
|
||||
#define STEP_LEN_TON_MIN 0x01
|
||||
#define STEP_MASK_TON_MIN 0x7F
|
||||
#define STEP_OFFSET_TON_MIN 0x0
|
||||
|
||||
#define STEP_REG_TOFF_MIN 0x10
|
||||
#define STEP_LEN_TOFF_MIN 0x01
|
||||
#define STEP_MASK_TOFF_MIN 0x7F
|
||||
#define STEP_OFFSET_TOFF_MIN 0x0
|
||||
|
||||
#define STEP_REG_ADC_OUT 0x12
|
||||
#define STEP_LEN_ADC_OUT 0x01
|
||||
#define STEP_MASK_ADC_OUT 0x1F
|
||||
#define STEP_OFFSET_ADC_OUT 0x0
|
||||
|
||||
#define STEP_REG_OCD_TH 0x13
|
||||
#define STEP_LEN_OCD_TH 0x01
|
||||
#define STEP_MASK_OCD_TH 0x0F
|
||||
#define STEP_OFFSET_OCD_TH 0x0
|
||||
|
||||
#define STEP_REG_STEP_MODE 0x16
|
||||
#define STEP_LEN_STEP_MODE 0x01
|
||||
#define STEP_MASK_STEP_MODE 0xFF
|
||||
#define STEP_OFFSET_STEP_MODE 0x0
|
||||
|
||||
#define STEP_REG_ALARM_EN 0x17
|
||||
#define STEP_LEN_ALARM_EN 0x01
|
||||
#define STEP_MASK_ALARM_EN 0xFF
|
||||
#define STEP_OFFSET_ALARM_EN 0x0
|
||||
|
||||
#define STEP_REG_CONFIG 0x18
|
||||
#define STEP_LEN_CONFIG 0x02
|
||||
#define STEP_MASK_CONFIG 0xFFFF
|
||||
#define STEP_OFFSET_CONFIG 0x0
|
||||
|
||||
#define STEP_REG_STATUS 0x19
|
||||
#define STEP_LEN_STATUS 0x02
|
||||
#define STEP_MASK_STATUS 0xFFFF
|
||||
#define STEP_OFFSET_STATUS 0x0
|
||||
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
typedef enum L6474x_AccessFlags
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
{
|
||||
afNONE = 0x00,
|
||||
afREAD = 0x01,
|
||||
afWRITE = 0x02,
|
||||
afWRITE_HighZ = 0x04
|
||||
} L6474x_AccessFlags_t;
|
||||
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
typedef struct L6474x_ParameterDescriptor
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
{
|
||||
unsigned char command;
|
||||
unsigned char defined;
|
||||
unsigned char length;
|
||||
unsigned int mask;
|
||||
char* address;
|
||||
L6474x_AccessFlags_t flags;
|
||||
} L6474x_ParameterDescriptor_t;
|
||||
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
static struct
|
||||
{
|
||||
int initialized;
|
||||
int state;
|
||||
int regPtr;
|
||||
int pending;
|
||||
int pwmGeneratorStarted;
|
||||
HANDLE pwmGeneratorHandle;
|
||||
struct
|
||||
{
|
||||
uint16_t status;
|
||||
uint32_t abs_pos;
|
||||
uint32_t el_pos;
|
||||
uint32_t mark;
|
||||
uint8_t ton;
|
||||
uint8_t toff;
|
||||
uint8_t tfast;
|
||||
uint8_t tval;
|
||||
uint8_t adc_out;
|
||||
uint8_t ocd_th;
|
||||
uint8_t step_mode;
|
||||
uint8_t alarm;
|
||||
uint16_t config;
|
||||
} regs;
|
||||
struct
|
||||
{
|
||||
int pwm_step;
|
||||
int spi_cs;
|
||||
int led_green;
|
||||
int led_red;
|
||||
int led_blue;
|
||||
int step_rst;
|
||||
int step_dir;
|
||||
int spindle_ena_b;
|
||||
int spindle_ena_f;
|
||||
int spindle_pwm_b;
|
||||
int spindle_pwm_f;
|
||||
} pins;
|
||||
} myConfig;
|
||||
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
static const L6474x_ParameterDescriptor_t L6474_Parameters[STEP_REG_RANGE_MASK]
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
= {
|
||||
[STEP_REG_ABS_POS] = {.command = STEP_REG_ABS_POS, .defined = 1, .length = STEP_LEN_ABS_POS, .mask = STEP_MASK_ABS_POS, .address = &myConfig.regs.abs_pos, .flags = afREAD | afWRITE },
|
||||
[STEP_REG_EL_POS] = {.command = STEP_REG_EL_POS, .defined = 1, .length = STEP_LEN_EL_POS, .mask = STEP_MASK_EL_POS, .address = &myConfig.regs.el_pos, .flags = afREAD | afWRITE },
|
||||
[STEP_REG_MARK] = {.command = STEP_REG_MARK, .defined = 1, .length = STEP_LEN_MARK, .mask = STEP_MASK_MARK, .address = &myConfig.regs.mark, .flags = afREAD | afWRITE },
|
||||
[STEP_REG_TVAL] = {.command = STEP_REG_TVAL, .defined = 1, .length = STEP_LEN_TVAL, .mask = STEP_MASK_TVAL, .address = &myConfig.regs.tval, .flags = afREAD | afWRITE },
|
||||
[STEP_REG_T_FAST] = {.command = STEP_REG_T_FAST, .defined = 1, .length = STEP_LEN_T_FAST, .mask = STEP_MASK_T_FAST, .address = &myConfig.regs.tfast, .flags = afREAD | afWRITE_HighZ },
|
||||
[STEP_REG_TON_MIN] = {.command = STEP_REG_TON_MIN, .defined = 1, .length = STEP_LEN_TON_MIN, .mask = STEP_MASK_TON_MIN, .address = &myConfig.regs.ton, .flags = afREAD | afWRITE_HighZ },
|
||||
[STEP_REG_TOFF_MIN] = {.command = STEP_REG_TOFF_MIN, .defined = 1, .length = STEP_LEN_TOFF_MIN, .mask = STEP_MASK_TOFF_MIN, .address = &myConfig.regs.toff, .flags = afREAD | afWRITE_HighZ },
|
||||
[STEP_REG_ADC_OUT] = {.command = STEP_REG_ADC_OUT, .defined = 1, .length = STEP_LEN_ADC_OUT, .mask = STEP_MASK_ADC_OUT, .address = &myConfig.regs.adc_out, .flags = afREAD },
|
||||
[STEP_REG_OCD_TH] = {.command = STEP_REG_OCD_TH, .defined = 1, .length = STEP_LEN_OCD_TH, .mask = STEP_MASK_OCD_TH, .address = &myConfig.regs.ocd_th, .flags = afREAD | afWRITE },
|
||||
[STEP_REG_STEP_MODE] = {.command = STEP_REG_STEP_MODE, .defined = 1, .length = STEP_LEN_STEP_MODE, .mask = STEP_MASK_STEP_MODE, .address = &myConfig.regs.step_mode, .flags = afREAD | afWRITE_HighZ },
|
||||
[STEP_REG_ALARM_EN] = {.command = STEP_REG_ALARM_EN, .defined = 1, .length = STEP_LEN_ALARM_EN, .mask = STEP_MASK_ALARM_EN, .address = &myConfig.regs.alarm, .flags = afREAD | afWRITE },
|
||||
[STEP_REG_CONFIG] = {.command = STEP_REG_CONFIG, .defined = 1, .length = STEP_LEN_CONFIG, .mask = STEP_MASK_CONFIG, .address = &myConfig.regs.config, .flags = afREAD | afWRITE_HighZ },
|
||||
[STEP_REG_STATUS] = {.command = STEP_REG_STATUS, .defined = 1, .length = STEP_LEN_STATUS, .mask = STEP_MASK_STATUS, .address = &myConfig.regs.status, .flags = afREAD }
|
||||
};
|
||||
|
||||
SPI_TypeDef __int_SPI1;
|
||||
SPI_TypeDef __int_SPI2;
|
||||
SPI_TypeDef __int_SPI3;
|
||||
SPI_TypeDef __int_SPI4;
|
||||
SPI_TypeDef __int_SPI5;
|
||||
SPI_TypeDef __int_SPI6;
|
||||
|
||||
TIM_TypeDef __int_TIM1;
|
||||
TIM_TypeDef __int_TIM2;
|
||||
TIM_TypeDef __int_TIM3;
|
||||
TIM_TypeDef __int_TIM4;
|
||||
TIM_TypeDef __int_TIM5;
|
||||
TIM_TypeDef __int_TIM6;
|
||||
TIM_TypeDef __int_TIM7;
|
||||
TIM_TypeDef __int_TIM8;
|
||||
TIM_TypeDef __int_TIM9;
|
||||
TIM_TypeDef __int_TIM10;
|
||||
TIM_TypeDef __int_TIM11;
|
||||
TIM_TypeDef __int_TIM12;
|
||||
TIM_TypeDef __int_TIM13;
|
||||
TIM_TypeDef __int_TIM14;
|
||||
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
static uint8_t ExecDriverProcessorSPI(uint8_t input);
|
||||
static uint8_t directionForward = 1;
|
||||
static int32_t internalPosition = 0;
|
||||
|
||||
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
GPIO_PinState HAL_GPIO_ReadPin(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin)
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
{
|
||||
if (GPIO_Pin == GPIO_PIN_15 && GPIOx == GPIOD) // stepper PWM pin
|
||||
{
|
||||
return myConfig.pins.pwm_step;
|
||||
}
|
||||
else if (GPIOx == GPIOC && GPIO_Pin == GPIO_PIN_13) // reference mark
|
||||
{
|
||||
return internalPosition >= 100;
|
||||
}
|
||||
else if (GPIO_Pin == GPIO_PIN_0 && GPIOx == GPIOB) // led green
|
||||
{
|
||||
return myConfig.pins.led_green;
|
||||
}
|
||||
else if (GPIO_Pin == GPIO_PIN_12 && GPIOx == GPIOF) // step reset
|
||||
{
|
||||
return myConfig.pins.step_rst;
|
||||
}
|
||||
else if (GPIO_Pin == GPIO_PIN_13 && GPIOx == GPIOF) // step dir
|
||||
{
|
||||
return myConfig.pins.step_dir;
|
||||
}
|
||||
else if (GPIO_Pin == GPIO_PIN_15 && GPIOx == GPIOF) // step flag
|
||||
{
|
||||
return GPIO_PIN_RESET;
|
||||
}
|
||||
else if (GPIO_Pin == GPIO_PIN_14 && GPIOx == GPIOE) // spindle ena back
|
||||
{
|
||||
return myConfig.pins.spindle_ena_b;
|
||||
}
|
||||
else if (GPIO_Pin == GPIO_PIN_15 && GPIOx == GPIOE) // spindle ena for
|
||||
{
|
||||
return myConfig.pins.spindle_ena_f;
|
||||
}
|
||||
else if (GPIO_Pin == GPIO_PIN_11 && GPIOx == GPIOB) // spindle pwm back
|
||||
{
|
||||
return myConfig.pins.spindle_pwm_b;
|
||||
}
|
||||
else if (GPIO_Pin == GPIO_PIN_10 && GPIOx == GPIOB) // spindle pwm for
|
||||
{
|
||||
return myConfig.pins.spindle_pwm_f;
|
||||
}
|
||||
else if (GPIO_Pin == GPIO_PIN_14 && GPIOx == GPIOB) // led red
|
||||
{
|
||||
return myConfig.pins.led_red;
|
||||
}
|
||||
else if (GPIO_Pin == GPIO_PIN_14 && GPIOx == GPIOD) // spi cs pin
|
||||
{
|
||||
return myConfig.pins.spi_cs;
|
||||
}
|
||||
else if (GPIO_Pin == GPIO_PIN_7 && GPIOx == GPIOB) // led blue
|
||||
{
|
||||
return myConfig.pins.led_blue;
|
||||
}
|
||||
|
||||
|
||||
return GPIO_PIN_RESET;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
void HAL_GPIO_WritePin(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, GPIO_PinState PinState)
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
{
|
||||
if (GPIO_Pin == GPIO_PIN_15 && GPIOx == GPIOD) // stepper PWM pin
|
||||
{
|
||||
if (myConfig.pins.pwm_step == 0 && PinState != 0)
|
||||
{
|
||||
if ((myConfig.regs.status & STATUS_HIGHZ_MASK) == 0)
|
||||
{
|
||||
if (directionForward) { internalPosition += 1; myConfig.regs.abs_pos += 1; }
|
||||
else { internalPosition -= 1; myConfig.regs.abs_pos -= 1; }
|
||||
if (internalPosition > 100) internalPosition = 100;
|
||||
if (internalPosition < -100) internalPosition = -100;
|
||||
}
|
||||
}
|
||||
myConfig.pins.pwm_step = !!PinState;
|
||||
}
|
||||
else if (GPIOx == GPIOC && GPIO_Pin == GPIO_PIN_13) // reference mark
|
||||
{
|
||||
return;
|
||||
}
|
||||
else if (GPIO_Pin == GPIO_PIN_0 && GPIOx == GPIOB) // led green
|
||||
{
|
||||
myConfig.pins.led_green = !!PinState;
|
||||
}
|
||||
else if (GPIO_Pin == GPIO_PIN_12 && GPIOx == GPIOF) // step reset
|
||||
{
|
||||
// do some preinitialization
|
||||
myConfig.pins.step_rst = !!PinState;
|
||||
if (PinState == GPIO_PIN_RESET)
|
||||
{
|
||||
myConfig.initialized = 1;
|
||||
myConfig.state = 0;
|
||||
myConfig.regs.abs_pos = 0;
|
||||
myConfig.regs.el_pos = 0;
|
||||
myConfig.regs.mark = 0;
|
||||
myConfig.regs.status = STATUS_HIGHZ_MASK | STATUS_OCD_MASK | STATUS_THR_SHORTD_MASK | STATUS_THR_WARN_MASK | STATUS_UNDERVOLT_MASK;
|
||||
}
|
||||
}
|
||||
else if (GPIO_Pin == GPIO_PIN_13 && GPIOx == GPIOF) // step dir
|
||||
{
|
||||
myConfig.pins.step_dir = !!PinState;
|
||||
if (PinState == GPIO_PIN_SET) myConfig.regs.status |= STATUS_DIRECTION_MASK;
|
||||
else myConfig.regs.status &= ~STATUS_DIRECTION_MASK;
|
||||
|
||||
if (PinState == GPIO_PIN_SET) directionForward = 1;
|
||||
else directionForward = 0;
|
||||
}
|
||||
else if (GPIO_Pin == GPIO_PIN_15 && GPIOx == GPIOF) // step flag
|
||||
{
|
||||
return;
|
||||
}
|
||||
else if (GPIO_Pin == GPIO_PIN_14 && GPIOx == GPIOE) // spindle ena back
|
||||
{
|
||||
myConfig.pins.spindle_ena_b = !!PinState;
|
||||
}
|
||||
else if (GPIO_Pin == GPIO_PIN_15 && GPIOx == GPIOE) // spindle ena for
|
||||
{
|
||||
myConfig.pins.spindle_ena_f = !!PinState;
|
||||
}
|
||||
else if (GPIO_Pin == GPIO_PIN_11 && GPIOx == GPIOB) // spindle pwm back
|
||||
{
|
||||
myConfig.pins.spindle_pwm_b = !!PinState;
|
||||
}
|
||||
else if (GPIO_Pin == GPIO_PIN_10 && GPIOx == GPIOB) // spindle pwm for
|
||||
{
|
||||
myConfig.pins.spindle_pwm_f = !!PinState;
|
||||
}
|
||||
else if (GPIO_Pin == GPIO_PIN_14 && GPIOx == GPIOB) // led red
|
||||
{
|
||||
myConfig.pins.led_red = !!PinState;
|
||||
}
|
||||
else if (GPIO_Pin == GPIO_PIN_14 && GPIOx == GPIOD) // spi cs pin
|
||||
{
|
||||
myConfig.pins.spi_cs = !!PinState;
|
||||
}
|
||||
else if (GPIO_Pin == GPIO_PIN_7 && GPIOx == GPIOB) // led blue
|
||||
{
|
||||
myConfig.pins.led_blue = !!PinState;
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
void HAL_GPIO_TogglePin(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin)
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
{
|
||||
if (GPIO_Pin == GPIO_PIN_15 && GPIOx == GPIOD) // stepper PWM pin
|
||||
{
|
||||
int tmp = !myConfig.pins.pwm_step;
|
||||
if (myConfig.pins.pwm_step == 0 && tmp != 0)
|
||||
{
|
||||
if ((myConfig.regs.status & STATUS_HIGHZ_MASK) == 0)
|
||||
{
|
||||
if (directionForward) { internalPosition += 1; myConfig.regs.abs_pos += 1; }
|
||||
else { internalPosition -= 1; myConfig.regs.abs_pos -= 1; }
|
||||
if (internalPosition > 100) internalPosition = 100;
|
||||
if (internalPosition < -100) internalPosition = -100;
|
||||
}
|
||||
}
|
||||
myConfig.pins.pwm_step = tmp;
|
||||
}
|
||||
else if (GPIO_Pin == GPIO_PIN_14 && GPIOx == GPIOD) // spi cs pin
|
||||
{
|
||||
myConfig.pins.spi_cs = !myConfig.pins.spi_cs;
|
||||
}
|
||||
else if (GPIOx == GPIOC && GPIO_Pin == GPIO_PIN_13) // reference mark
|
||||
{
|
||||
return;
|
||||
}
|
||||
else if (GPIO_Pin == GPIO_PIN_0 && GPIOx == GPIOB) // led green
|
||||
{
|
||||
myConfig.pins.led_green = !myConfig.pins.led_green;
|
||||
}
|
||||
else if (GPIO_Pin == GPIO_PIN_12 && GPIOx == GPIOF) // step reset
|
||||
{
|
||||
// do some preinitialization
|
||||
myConfig.pins.step_rst = !myConfig.pins.step_rst;
|
||||
if (myConfig.pins.step_rst == GPIO_PIN_RESET)
|
||||
{
|
||||
myConfig.initialized = 1;
|
||||
myConfig.state = 0;
|
||||
myConfig.regs.abs_pos = 0;
|
||||
myConfig.regs.el_pos = 0;
|
||||
myConfig.regs.mark = 0;
|
||||
myConfig.regs.status = STATUS_HIGHZ_MASK | STATUS_OCD_MASK | STATUS_THR_SHORTD_MASK | STATUS_THR_WARN_MASK | STATUS_UNDERVOLT_MASK;
|
||||
}
|
||||
}
|
||||
else if (GPIO_Pin == GPIO_PIN_13 && GPIOx == GPIOF) // step dir
|
||||
{
|
||||
myConfig.pins.step_dir = !myConfig.pins.step_dir;
|
||||
if (myConfig.pins.step_dir == GPIO_PIN_SET) myConfig.regs.status |= STATUS_DIRECTION_MASK;
|
||||
else myConfig.regs.status &= ~STATUS_DIRECTION_MASK;
|
||||
|
||||
if (myConfig.pins.step_dir == GPIO_PIN_SET) directionForward = 1;
|
||||
else directionForward = 0;
|
||||
}
|
||||
else if (GPIO_Pin == GPIO_PIN_15 && GPIOx == GPIOF) // step flag
|
||||
{
|
||||
return;
|
||||
}
|
||||
else if (GPIO_Pin == GPIO_PIN_14 && GPIOx == GPIOE) // spindle ena back
|
||||
{
|
||||
myConfig.pins.spindle_ena_b = !myConfig.pins.spindle_ena_b;
|
||||
}
|
||||
else if (GPIO_Pin == GPIO_PIN_15 && GPIOx == GPIOE) // spindle ena for
|
||||
{
|
||||
myConfig.pins.spindle_ena_f = !myConfig.pins.spindle_ena_f;
|
||||
}
|
||||
else if (GPIO_Pin == GPIO_PIN_11 && GPIOx == GPIOB) // spindle pwm back
|
||||
{
|
||||
myConfig.pins.spindle_pwm_b = !myConfig.pins.spindle_pwm_b;
|
||||
}
|
||||
else if (GPIO_Pin == GPIO_PIN_10 && GPIOx == GPIOB) // spindle pwm for
|
||||
{
|
||||
myConfig.pins.spindle_pwm_f = !myConfig.pins.spindle_pwm_f;
|
||||
}
|
||||
else if (GPIO_Pin == GPIO_PIN_14 && GPIOx == GPIOB) // led red
|
||||
{
|
||||
myConfig.pins.led_red = !myConfig.pins.led_red;
|
||||
}
|
||||
else if (GPIO_Pin == GPIO_PIN_14 && GPIOx == GPIOD) // spi cs pin
|
||||
{
|
||||
myConfig.pins.spi_cs = !myConfig.pins.spi_cs;
|
||||
}
|
||||
else if (GPIO_Pin == GPIO_PIN_7 && GPIOx == GPIOB) // led blue
|
||||
{
|
||||
myConfig.pins.led_blue = !myConfig.pins.led_blue;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
HAL_StatusTypeDef HAL_SPI_TransmitReceive(SPI_HandleTypeDef* hspi, uint8_t* pTxData, uint8_t* pRxData, uint16_t Size,
|
||||
uint32_t Timeout)
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
{
|
||||
if (hspi->Instance == SPI1)
|
||||
{
|
||||
// here we have to push the byte into the processor and then we have to write the response into tx byte
|
||||
*pRxData = ExecDriverProcessorSPI(*pTxData);
|
||||
}
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
#if !defined(USE_PWM_GENERATOR_DIRECTLY_INSTEAD_OF_GATING_SLAVE)
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
DWORD WINAPI ApplnMessageDispatcherThreadTIM1(LPVOID lpParameter)
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
{
|
||||
extern void HAL_TIM_PWM_PulseFinishedCallback(TIM_HandleTypeDef * htim);
|
||||
extern TIM_HandleTypeDef htim1;
|
||||
|
||||
Sleep(1000);
|
||||
TIM1->SR |= (1 << 2);
|
||||
HAL_TIM_PWM_PulseFinishedCallback(&htim1);
|
||||
|
||||
if ((myConfig.regs.status & STATUS_HIGHZ_MASK) == 0)
|
||||
{
|
||||
if (directionForward)
|
||||
{
|
||||
internalPosition += ((int32_t)TIM1->ARR + 1);
|
||||
myConfig.regs.abs_pos += (TIM1->ARR + 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
internalPosition -= (TIM1->ARR + 1);
|
||||
myConfig.regs.abs_pos -= (TIM1->ARR + 1);
|
||||
}
|
||||
|
||||
if (internalPosition > 100) internalPosition = 100;
|
||||
if (internalPosition < -100) internalPosition = -100;
|
||||
TIM1->ARR = 0;
|
||||
}
|
||||
|
||||
Sleep(100);
|
||||
TIM1->SR &= ~(1 << 2);
|
||||
HAL_TIM_PWM_PulseFinishedCallback(&htim1);
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(USE_PWM_GENERATOR_DIRECTLY_INSTEAD_OF_GATING_SLAVE)
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
DWORD WINAPI ApplnMessageDispatcherThreadTIM4(LPVOID lpParameter)
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
{
|
||||
extern void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef * htim);
|
||||
extern TIM_HandleTypeDef htim4;
|
||||
|
||||
while (myConfig.pwmGeneratorStarted)
|
||||
{
|
||||
Sleep(1);
|
||||
if (!myConfig.pwmGeneratorStarted) break;
|
||||
|
||||
if ((myConfig.regs.status & STATUS_HIGHZ_MASK) == 0)
|
||||
{
|
||||
if (directionForward)
|
||||
{
|
||||
internalPosition += 1;
|
||||
myConfig.regs.abs_pos += 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
internalPosition -= 1;
|
||||
myConfig.regs.abs_pos -= 1;
|
||||
}
|
||||
|
||||
if (internalPosition > 100) internalPosition = 100;
|
||||
if (internalPosition < -100) internalPosition = -100;
|
||||
}
|
||||
HAL_TIM_PeriodElapsedCallback(&htim4);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
HAL_StatusTypeDef HAL_TIM_OnePulse_Start_IT(TIM_HandleTypeDef* htim, uint32_t OutputChannel)
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
{
|
||||
#if !defined(USE_PWM_GENERATOR_DIRECTLY_INSTEAD_OF_GATING_SLAVE)
|
||||
if (htim->Instance == TIM1) // is the gating timer which enables the tim4 pwm generator
|
||||
{
|
||||
CreateThread(0, 0, ApplnMessageDispatcherThreadTIM1, NULL, 0, NULL);
|
||||
}
|
||||
return HAL_OK;
|
||||
#endif
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
HAL_StatusTypeDef HAL_TIM_OnePulse_Stop_IT(TIM_HandleTypeDef* htim, uint32_t OutputChannel)
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
{
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
HAL_StatusTypeDef HAL_TIM_GenerateEvent(TIM_HandleTypeDef* htim, uint32_t EventSource)
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
{
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
HAL_StatusTypeDef HAL_TIM_OnePulse_Stop(TIM_HandleTypeDef* htim, uint32_t OutputChannel)
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
{
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
HAL_StatusTypeDef HAL_TIM_PWM_Start(TIM_HandleTypeDef* htim, uint32_t Channel)
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
{
|
||||
#if defined(USE_PWM_GENERATOR_DIRECTLY_INSTEAD_OF_GATING_SLAVE)
|
||||
if (htim->Instance == TIM4) // is the pwm generator
|
||||
{
|
||||
if (myConfig.pwmGeneratorStarted == 0)
|
||||
{
|
||||
// this blocks until the thread has exited
|
||||
if (myConfig.pwmGeneratorHandle) WaitForSingleObject(myConfig.pwmGeneratorHandle, INFINITE);
|
||||
|
||||
myConfig.pwmGeneratorStarted = 1;
|
||||
myConfig.pwmGeneratorHandle = CreateThread(0, 0, ApplnMessageDispatcherThreadTIM4, NULL, 0, NULL);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
HAL_StatusTypeDef HAL_TIM_PWM_Start_IT(TIM_HandleTypeDef* htim, uint32_t Channel)
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
{
|
||||
HAL_TIM_PWM_Start(htim, Channel);
|
||||
//TODO: here the interrupt enable bit must be set correctly
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
HAL_StatusTypeDef HAL_TIM_PWM_Stop(TIM_HandleTypeDef* htim, uint32_t Channel)
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
{
|
||||
myConfig.pwmGeneratorStarted = 0;
|
||||
#if defined(USE_PWM_GENERATOR_DIRECTLY_INSTEAD_OF_GATING_SLAVE)
|
||||
Sleep(10);
|
||||
if (myConfig.pwmGeneratorHandle != NULL)
|
||||
{
|
||||
//TODO: hier muss anders gestoppt werden
|
||||
WaitForSingleObject(myConfig.pwmGeneratorHandle, INFINITE); // this blocks until the thread has exited
|
||||
}
|
||||
#endif
|
||||
myConfig.pwmGeneratorHandle = NULL;
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
HAL_StatusTypeDef HAL_TIM_PWM_ConfigChannel(TIM_HandleTypeDef* htim, const TIM_OC_InitTypeDef* sConfig,uint32_t Channel)
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
{
|
||||
if (Channel == TIM_CHANNEL_1) htim->Instance->CCR1 = sConfig->Pulse;
|
||||
else if (Channel == TIM_CHANNEL_2) htim->Instance->CCR2 = sConfig->Pulse;
|
||||
else if (Channel == TIM_CHANNEL_3) htim->Instance->CCR3 = sConfig->Pulse;
|
||||
else if (Channel == TIM_CHANNEL_4) htim->Instance->CCR4 = sConfig->Pulse;
|
||||
else if (Channel == TIM_CHANNEL_5) htim->Instance->CCR5 = sConfig->Pulse;
|
||||
else if (Channel == TIM_CHANNEL_6) htim->Instance->CCR6 = sConfig->Pulse;
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
HAL_StatusTypeDef HAL_TIM_Base_Init(TIM_HandleTypeDef* htim)
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
{
|
||||
htim->Instance->ARR = htim->Init.Period;
|
||||
htim->Instance->PSC = htim->Init.Prescaler;
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
static uint8_t ExecDriverProcessorSPI(uint8_t input)
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
{
|
||||
if (myConfig.initialized == 0)
|
||||
{
|
||||
// do some preinitialization
|
||||
myConfig.initialized = 1;
|
||||
myConfig.state = 0;
|
||||
myConfig.regs.abs_pos = 0;
|
||||
myConfig.regs.el_pos = 0;
|
||||
myConfig.regs.mark = 0;
|
||||
myConfig.regs.status = STATUS_HIGHZ_MASK | STATUS_OCD_MASK | STATUS_THR_SHORTD_MASK | STATUS_THR_WARN_MASK | STATUS_UNDERVOLT_MASK;
|
||||
}
|
||||
|
||||
uint8_t output = STEP_CMD_NOP_PREFIX;
|
||||
|
||||
switch (myConfig.state)
|
||||
{
|
||||
case 0x00:
|
||||
if (input == STEP_CMD_STA_PREFIX)
|
||||
myConfig.state = 0x50;
|
||||
else if (input == STEP_CMD_ENA_PREFIX)
|
||||
myConfig.regs.status &= ~STATUS_HIGHZ_MASK;
|
||||
else if (input == STEP_CMD_DIS_PREFIX)
|
||||
myConfig.regs.status |= STATUS_HIGHZ_MASK;
|
||||
else if ((input & STEP_REG_CMD_MASK) == STEP_CMD_GET_PREFIX) {
|
||||
myConfig.regPtr = input & STEP_REG_RANGE_MASK;
|
||||
myConfig.pending = L6474_Parameters[myConfig.regPtr].length;
|
||||
myConfig.state = 0x20 + myConfig.pending - 1;
|
||||
}
|
||||
else if ((input & STEP_REG_CMD_MASK) == STEP_CMD_SET_PREFIX) {
|
||||
myConfig.regPtr = input & STEP_REG_RANGE_MASK;
|
||||
myConfig.pending = L6474_Parameters[myConfig.regPtr].length;
|
||||
myConfig.state = 0x10 + myConfig.pending - 1;
|
||||
}
|
||||
break;
|
||||
|
||||
// part of register set
|
||||
case 0x10:
|
||||
if (((myConfig.regs.status & STATUS_HIGHZ_MASK) == 0) && (L6474_Parameters[myConfig.regPtr].flags & afWRITE_HighZ))
|
||||
{
|
||||
myConfig.regs.status |= STATUS_NOTPERF_CMD_MASK;
|
||||
}
|
||||
else
|
||||
{
|
||||
*(L6474_Parameters[myConfig.regPtr].address + 0) = input;
|
||||
}
|
||||
output = *(L6474_Parameters[myConfig.regPtr].address + 0);
|
||||
myConfig.state = 0x00;
|
||||
break;
|
||||
|
||||
case 0x11:
|
||||
if (((myConfig.regs.status & STATUS_HIGHZ_MASK) == 0) && (L6474_Parameters[myConfig.regPtr].flags & afWRITE_HighZ))
|
||||
{
|
||||
myConfig.regs.status |= STATUS_NOTPERF_CMD_MASK;
|
||||
}
|
||||
else
|
||||
{
|
||||
*(L6474_Parameters[myConfig.regPtr].address + 1) = input;
|
||||
}
|
||||
output = *(L6474_Parameters[myConfig.regPtr].address + 1);
|
||||
myConfig.state = 0x10;
|
||||
break;
|
||||
|
||||
case 0x12:
|
||||
if (((myConfig.regs.status & STATUS_HIGHZ_MASK) == 0) && (L6474_Parameters[myConfig.regPtr].flags & afWRITE_HighZ))
|
||||
{
|
||||
myConfig.regs.status |= STATUS_NOTPERF_CMD_MASK;
|
||||
}
|
||||
else
|
||||
{
|
||||
*(L6474_Parameters[myConfig.regPtr].address + 2) = input;
|
||||
}
|
||||
output = *(L6474_Parameters[myConfig.regPtr].address + 2);
|
||||
myConfig.state = 0x11;
|
||||
break;
|
||||
|
||||
// part of register get
|
||||
case 0x20:
|
||||
output = *(L6474_Parameters[myConfig.regPtr].address + 0);
|
||||
myConfig.state = 0x00;
|
||||
break;
|
||||
|
||||
case 0x21:
|
||||
output = *(L6474_Parameters[myConfig.regPtr].address + 1);
|
||||
myConfig.state = 0x20;
|
||||
break;
|
||||
|
||||
case 0x22:
|
||||
output = *(L6474_Parameters[myConfig.regPtr].address + 2);
|
||||
myConfig.state = 0x21;
|
||||
break;
|
||||
|
||||
// part of status get
|
||||
case 0x50:
|
||||
output = myConfig.regs.status >> 8;
|
||||
myConfig.state = 0x51;
|
||||
break;
|
||||
|
||||
case 0x51:
|
||||
output = myConfig.regs.status;
|
||||
myConfig.state = 0x00;
|
||||
break;
|
||||
|
||||
default:
|
||||
myConfig.state = 0x00;
|
||||
myConfig.regs.status |= STATUS_WRONG_CMD_MASK;
|
||||
break;
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
Reference in new issue
Block a user