fix i2c error, add senser interface.
This commit is contained in:
@@ -42,7 +42,7 @@ Modification:
|
||||
|
||||
static I2cBusParam i2c_bus_param =
|
||||
{
|
||||
I2C_SDA_FUNC_GPIO,
|
||||
_FUNC_GPIO,
|
||||
I2C_SCL_FUNC_GPIO,
|
||||
};
|
||||
static BusType pin;
|
||||
|
||||
@@ -1256,7 +1256,7 @@ status_t LPI2C_MasterTransferNonBlocking(LPI2C_Type *base,
|
||||
|
||||
/* Return an error if the bus is already in use not by us. */
|
||||
result = LPI2C_CheckForBusyBus(base);
|
||||
if (result)
|
||||
if (result != kStatus_Success)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -11,6 +11,8 @@
|
||||
#include <string.h>
|
||||
#include <xs_isr.h>
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
* Definitions
|
||||
******************************************************************************/
|
||||
@@ -982,6 +984,8 @@ void LPI2C_MasterTransferCreateHandle(LPI2C_Type *base,
|
||||
EnableIRQ(kLpi2cIrqs[instance]);
|
||||
}
|
||||
|
||||
|
||||
uint32_t failed_times = 0;
|
||||
/*!
|
||||
* @brief Execute states until FIFOs are exhausted.
|
||||
* @param handle Master nonblocking driver handle.
|
||||
@@ -1018,6 +1022,13 @@ static status_t LPI2C_RunTransferStateMachine(LPI2C_Type *base, lpi2c_master_han
|
||||
|
||||
/* Get fifo counts and compute room in tx fifo. */
|
||||
LPI2C_MasterGetFifoCounts(base, &rxCount, &txCount);
|
||||
if (txCount == 0 && rxCount == 0) {
|
||||
failed_times++;
|
||||
if (failed_times > 100) {
|
||||
handle->state = kStopState;
|
||||
failed_times = 0;
|
||||
}
|
||||
}
|
||||
txCount = txFifoSize - txCount;
|
||||
|
||||
while (!state_complete)
|
||||
@@ -1148,6 +1159,7 @@ static status_t LPI2C_RunTransferStateMachine(LPI2C_Type *base, lpi2c_master_han
|
||||
if (status & kLPI2C_MasterStopDetectFlag)
|
||||
{
|
||||
*isDone = true;
|
||||
failed_times = 0;
|
||||
}
|
||||
state_complete = true;
|
||||
break;
|
||||
@@ -1372,6 +1384,7 @@ void LPI2C_MasterTransferAbort(LPI2C_Type *base, lpi2c_master_handle_t *handle)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*!
|
||||
* brief Reusable routine to handle master interrupts.
|
||||
* note This function does not need to be called unless you are reimplementing the
|
||||
@@ -1396,11 +1409,11 @@ void LPI2C_MasterTransferHandleIRQ(LPI2C_Type *base, lpi2c_master_handle_t *hand
|
||||
}
|
||||
|
||||
result = LPI2C_RunTransferStateMachine(base, handle, &isDone);
|
||||
|
||||
|
||||
if (isDone || (result != kStatus_Success))
|
||||
{
|
||||
/* XXX need to handle data that may be in rx fifo below watermark level? */
|
||||
|
||||
|
||||
/* XXX handle error, terminate xfer */
|
||||
|
||||
/* Disable internal IRQ enables. */
|
||||
@@ -2113,9 +2126,7 @@ void LPI2C0_DriverIRQHandler(void)
|
||||
/* Implementation of LPI2C1 handler named in startup code. */
|
||||
void LPI2C1_DriverIRQHandler(int irqn, void *arg)
|
||||
{
|
||||
DisableIRQ(LPI2C1_IRQn);
|
||||
LPI2C_CommonIRQHandler(LPI2C1, 1);
|
||||
EnableIRQ(LPI2C1_IRQn);
|
||||
}
|
||||
DECLARE_HW_IRQ(LPI2C1_IRQn, LPI2C1_DriverIRQHandler, NONE);
|
||||
#endif
|
||||
|
||||
@@ -27,7 +27,6 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
typedef struct Stm32I2c
|
||||
{
|
||||
LPI2C_Type* base;
|
||||
|
||||
@@ -0,0 +1,476 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Freescale Semiconductor, Inc.
|
||||
* Copyright 2016-2017 NXP
|
||||
* All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
/*************************************************
|
||||
File name: fsl_port
|
||||
Description:
|
||||
Others: take for references
|
||||
https://github.com/open-isa-org/open-isa.org
|
||||
History:
|
||||
1. Date: 2022-02-16
|
||||
Author: AIIT XUOS Lab
|
||||
Modification:
|
||||
*************************************************/
|
||||
|
||||
#ifndef _FSL_PORT_H_
|
||||
#define _FSL_PORT_H_
|
||||
|
||||
#include "fsl_common.h"
|
||||
|
||||
/*!
|
||||
* @addtogroup port
|
||||
* @{
|
||||
*/
|
||||
|
||||
/*******************************************************************************
|
||||
* Definitions
|
||||
******************************************************************************/
|
||||
|
||||
/*! @name Driver version */
|
||||
/*@{*/
|
||||
/*! Version 2.0.2. */
|
||||
#define FSL_PORT_DRIVER_VERSION (MAKE_VERSION(2, 0, 2))
|
||||
/*@}*/
|
||||
|
||||
#if defined(FSL_FEATURE_PORT_HAS_PULL_ENABLE) && FSL_FEATURE_PORT_HAS_PULL_ENABLE
|
||||
/*! @brief Internal resistor pull feature selection */
|
||||
enum _port_pull
|
||||
{
|
||||
kPORT_PullDisable = 0U, /*!< Internal pull-up/down resistor is disabled. */
|
||||
kPORT_PullDown = 2U, /*!< Internal pull-down resistor is enabled. */
|
||||
kPORT_PullUp = 3U, /*!< Internal pull-up resistor is enabled. */
|
||||
};
|
||||
#endif /* FSL_FEATURE_PORT_HAS_PULL_ENABLE */
|
||||
|
||||
#if defined(FSL_FEATURE_PORT_HAS_SLEW_RATE) && FSL_FEATURE_PORT_HAS_SLEW_RATE
|
||||
/*! @brief Slew rate selection */
|
||||
enum _port_slew_rate
|
||||
{
|
||||
kPORT_FastSlewRate = 0U, /*!< Fast slew rate is configured. */
|
||||
kPORT_SlowSlewRate = 1U, /*!< Slow slew rate is configured. */
|
||||
};
|
||||
#endif /* FSL_FEATURE_PORT_HAS_SLEW_RATE */
|
||||
|
||||
#if defined(FSL_FEATURE_PORT_HAS_OPEN_DRAIN) && FSL_FEATURE_PORT_HAS_OPEN_DRAIN
|
||||
/*! @brief Open Drain feature enable/disable */
|
||||
enum _port_open_drain_enable
|
||||
{
|
||||
kPORT_OpenDrainDisable = 0U, /*!< Open drain output is disabled. */
|
||||
kPORT_OpenDrainEnable = 1U, /*!< Open drain output is enabled. */
|
||||
};
|
||||
#endif /* FSL_FEATURE_PORT_HAS_OPEN_DRAIN */
|
||||
|
||||
#if defined(FSL_FEATURE_PORT_HAS_PASSIVE_FILTER) && FSL_FEATURE_PORT_HAS_PASSIVE_FILTER
|
||||
/*! @brief Passive filter feature enable/disable */
|
||||
enum _port_passive_filter_enable
|
||||
{
|
||||
kPORT_PassiveFilterDisable = 0U, /*!< Passive input filter is disabled. */
|
||||
kPORT_PassiveFilterEnable = 1U, /*!< Passive input filter is enabled. */
|
||||
};
|
||||
#endif
|
||||
|
||||
#if defined(FSL_FEATURE_PORT_HAS_DRIVE_STRENGTH) && FSL_FEATURE_PORT_HAS_DRIVE_STRENGTH
|
||||
/*! @brief Configures the drive strength. */
|
||||
enum _port_drive_strength
|
||||
{
|
||||
kPORT_LowDriveStrength = 0U, /*!< Low-drive strength is configured. */
|
||||
kPORT_HighDriveStrength = 1U, /*!< High-drive strength is configured. */
|
||||
};
|
||||
#endif /* FSL_FEATURE_PORT_HAS_DRIVE_STRENGTH */
|
||||
|
||||
#if defined(FSL_FEATURE_PORT_HAS_PIN_CONTROL_LOCK) && FSL_FEATURE_PORT_HAS_PIN_CONTROL_LOCK
|
||||
/*! @brief Unlock/lock the pin control register field[15:0] */
|
||||
enum _port_lock_register
|
||||
{
|
||||
kPORT_UnlockRegister = 0U, /*!< Pin Control Register fields [15:0] are not locked. */
|
||||
kPORT_LockRegister = 1U, /*!< Pin Control Register fields [15:0] are locked. */
|
||||
};
|
||||
#endif /* FSL_FEATURE_PORT_HAS_PIN_CONTROL_LOCK */
|
||||
|
||||
#if defined(FSL_FEATURE_PORT_PCR_MUX_WIDTH) && FSL_FEATURE_PORT_PCR_MUX_WIDTH
|
||||
/*! @brief Pin mux selection */
|
||||
typedef enum _port_mux
|
||||
{
|
||||
kPORT_PinDisabledOrAnalog = 0U, /*!< Corresponding pin is disabled, but is used as an analog pin. */
|
||||
kPORT_MuxAsGpio = 1U, /*!< Corresponding pin is configured as GPIO. */
|
||||
kPORT_MuxAlt2 = 2U, /*!< Chip-specific */
|
||||
kPORT_MuxAlt3 = 3U, /*!< Chip-specific */
|
||||
kPORT_MuxAlt4 = 4U, /*!< Chip-specific */
|
||||
kPORT_MuxAlt5 = 5U, /*!< Chip-specific */
|
||||
kPORT_MuxAlt6 = 6U, /*!< Chip-specific */
|
||||
kPORT_MuxAlt7 = 7U, /*!< Chip-specific */
|
||||
kPORT_MuxAlt8 = 8U, /*!< Chip-specific */
|
||||
kPORT_MuxAlt9 = 9U, /*!< Chip-specific */
|
||||
kPORT_MuxAlt10 = 10U, /*!< Chip-specific */
|
||||
kPORT_MuxAlt11 = 11U, /*!< Chip-specific */
|
||||
kPORT_MuxAlt12 = 12U, /*!< Chip-specific */
|
||||
kPORT_MuxAlt13 = 13U, /*!< Chip-specific */
|
||||
kPORT_MuxAlt14 = 14U, /*!< Chip-specific */
|
||||
kPORT_MuxAlt15 = 15U, /*!< Chip-specific */
|
||||
} port_mux_t;
|
||||
#endif /* FSL_FEATURE_PORT_PCR_MUX_WIDTH */
|
||||
|
||||
/*! @brief Configures the interrupt generation condition. */
|
||||
typedef enum _port_interrupt
|
||||
{
|
||||
kPORT_InterruptOrDMADisabled = 0x0U, /*!< Interrupt/DMA request is disabled. */
|
||||
#if defined(FSL_FEATURE_PORT_HAS_DMA_REQUEST) && FSL_FEATURE_PORT_HAS_DMA_REQUEST
|
||||
kPORT_DMARisingEdge = 0x1U, /*!< DMA request on rising edge. */
|
||||
kPORT_DMAFallingEdge = 0x2U, /*!< DMA request on falling edge. */
|
||||
kPORT_DMAEitherEdge = 0x3U, /*!< DMA request on either edge. */
|
||||
#endif
|
||||
#if defined(FSL_FEATURE_PORT_HAS_IRQC_FLAG) && FSL_FEATURE_PORT_HAS_IRQC_FLAG
|
||||
kPORT_FlagRisingEdge = 0x05U, /*!< Flag sets on rising edge. */
|
||||
kPORT_FlagFallingEdge = 0x06U, /*!< Flag sets on falling edge. */
|
||||
kPORT_FlagEitherEdge = 0x07U, /*!< Flag sets on either edge. */
|
||||
#endif
|
||||
kPORT_InterruptLogicZero = 0x8U, /*!< Interrupt when logic zero. */
|
||||
kPORT_InterruptRisingEdge = 0x9U, /*!< Interrupt on rising edge. */
|
||||
kPORT_InterruptFallingEdge = 0xAU, /*!< Interrupt on falling edge. */
|
||||
kPORT_InterruptEitherEdge = 0xBU, /*!< Interrupt on either edge. */
|
||||
kPORT_InterruptLogicOne = 0xCU, /*!< Interrupt when logic one. */
|
||||
#if defined(FSL_FEATURE_PORT_HAS_IRQC_TRIGGER) && FSL_FEATURE_PORT_HAS_IRQC_TRIGGER
|
||||
kPORT_ActiveHighTriggerOutputEnable = 0xDU, /*!< Enable active high-trigger output. */
|
||||
kPORT_ActiveLowTriggerOutputEnable = 0xEU, /*!< Enable active low-trigger output. */
|
||||
#endif
|
||||
} port_interrupt_t;
|
||||
|
||||
#if defined(FSL_FEATURE_PORT_HAS_DIGITAL_FILTER) && FSL_FEATURE_PORT_HAS_DIGITAL_FILTER
|
||||
/*! @brief Digital filter clock source selection */
|
||||
typedef enum _port_digital_filter_clock_source
|
||||
{
|
||||
kPORT_BusClock = 0U, /*!< Digital filters are clocked by the bus clock. */
|
||||
kPORT_LpoClock = 1U, /*!< Digital filters are clocked by the 1 kHz LPO clock. */
|
||||
} port_digital_filter_clock_source_t;
|
||||
|
||||
/*! @brief PORT digital filter feature configuration definition */
|
||||
typedef struct _port_digital_filter_config
|
||||
{
|
||||
uint32_t digitalFilterWidth; /*!< Set digital filter width */
|
||||
port_digital_filter_clock_source_t clockSource; /*!< Set digital filter clockSource */
|
||||
} port_digital_filter_config_t;
|
||||
#endif /* FSL_FEATURE_PORT_HAS_DIGITAL_FILTER */
|
||||
|
||||
#if defined(FSL_FEATURE_PORT_PCR_MUX_WIDTH) && FSL_FEATURE_PORT_PCR_MUX_WIDTH
|
||||
/*! @brief PORT pin configuration structure */
|
||||
typedef struct _port_pin_config
|
||||
{
|
||||
#if defined(FSL_FEATURE_PORT_HAS_PULL_ENABLE) && FSL_FEATURE_PORT_HAS_PULL_ENABLE
|
||||
uint16_t pullSelect : 2; /*!< No-pull/pull-down/pull-up select */
|
||||
#else
|
||||
uint16_t : 2;
|
||||
#endif /* FSL_FEATURE_PORT_HAS_PULL_ENABLE */
|
||||
|
||||
#if defined(FSL_FEATURE_PORT_HAS_SLEW_RATE) && FSL_FEATURE_PORT_HAS_SLEW_RATE
|
||||
uint16_t slewRate : 1; /*!< Fast/slow slew rate Configure */
|
||||
#else
|
||||
uint16_t : 1;
|
||||
#endif /* FSL_FEATURE_PORT_HAS_SLEW_RATE */
|
||||
|
||||
uint16_t : 1;
|
||||
|
||||
#if defined(FSL_FEATURE_PORT_HAS_PASSIVE_FILTER) && FSL_FEATURE_PORT_HAS_PASSIVE_FILTER
|
||||
uint16_t passiveFilterEnable : 1; /*!< Passive filter enable/disable */
|
||||
#else
|
||||
uint16_t : 1;
|
||||
#endif /* FSL_FEATURE_PORT_HAS_PASSIVE_FILTER */
|
||||
|
||||
#if defined(FSL_FEATURE_PORT_HAS_OPEN_DRAIN) && FSL_FEATURE_PORT_HAS_OPEN_DRAIN
|
||||
uint16_t openDrainEnable : 1; /*!< Open drain enable/disable */
|
||||
#else
|
||||
uint16_t : 1;
|
||||
#endif /* FSL_FEATURE_PORT_HAS_OPEN_DRAIN */
|
||||
|
||||
#if defined(FSL_FEATURE_PORT_HAS_DRIVE_STRENGTH) && FSL_FEATURE_PORT_HAS_DRIVE_STRENGTH
|
||||
uint16_t driveStrength : 1; /*!< Fast/slow drive strength configure */
|
||||
#else
|
||||
uint16_t : 1;
|
||||
#endif
|
||||
|
||||
uint16_t : 1;
|
||||
|
||||
#if defined(FSL_FEATURE_PORT_PCR_MUX_WIDTH) && (FSL_FEATURE_PORT_PCR_MUX_WIDTH == 3)
|
||||
uint16_t mux : 3; /*!< Pin mux Configure */
|
||||
uint16_t : 4;
|
||||
#elif defined(FSL_FEATURE_PORT_PCR_MUX_WIDTH) && (FSL_FEATURE_PORT_PCR_MUX_WIDTH == 4)
|
||||
uint16_t mux : 4; /*!< Pin mux Configure */
|
||||
uint16_t : 3;
|
||||
#else
|
||||
uint16_t : 7,
|
||||
#endif
|
||||
|
||||
#if defined(FSL_FEATURE_PORT_HAS_PIN_CONTROL_LOCK) && FSL_FEATURE_PORT_HAS_PIN_CONTROL_LOCK
|
||||
uint16_t lockRegister : 1; /*!< Lock/unlock the PCR field[15:0] */
|
||||
#else
|
||||
uint16_t : 1;
|
||||
#endif /* FSL_FEATURE_PORT_HAS_PIN_CONTROL_LOCK */
|
||||
} port_pin_config_t;
|
||||
#endif /* FSL_FEATURE_PORT_PCR_MUX_WIDTH */
|
||||
|
||||
/*******************************************************************************
|
||||
* API
|
||||
******************************************************************************/
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#if defined(FSL_FEATURE_PORT_PCR_MUX_WIDTH) && FSL_FEATURE_PORT_PCR_MUX_WIDTH
|
||||
/*! @name Configuration */
|
||||
/*@{*/
|
||||
|
||||
/*!
|
||||
* @brief Sets the port PCR register.
|
||||
*
|
||||
* This is an example to define an input pin or output pin PCR configuration.
|
||||
* @code
|
||||
* // Define a digital input pin PCR configuration
|
||||
* port_pin_config_t config = {
|
||||
* kPORT_PullUp,
|
||||
* kPORT_FastSlewRate,
|
||||
* kPORT_PassiveFilterDisable,
|
||||
* kPORT_OpenDrainDisable,
|
||||
* kPORT_LowDriveStrength,
|
||||
* kPORT_MuxAsGpio,
|
||||
* kPORT_UnLockRegister,
|
||||
* };
|
||||
* @endcode
|
||||
*
|
||||
* @param base PORT peripheral base pointer.
|
||||
* @param pin PORT pin number.
|
||||
* @param config PORT PCR register configuration structure.
|
||||
*/
|
||||
static inline void PORT_SetPinConfig(PORT_Type *base, uint32_t pin, const port_pin_config_t *config)
|
||||
{
|
||||
assert(config);
|
||||
uint32_t addr = (uint32_t)&base->PCR[pin];
|
||||
*(volatile uint16_t *)(addr) = *((const uint16_t *)config);
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Sets the port PCR register for multiple pins.
|
||||
*
|
||||
* This is an example to define input pins or output pins PCR configuration.
|
||||
* @code
|
||||
* // Define a digital input pin PCR configuration
|
||||
* port_pin_config_t config = {
|
||||
* kPORT_PullUp ,
|
||||
* kPORT_PullEnable,
|
||||
* kPORT_FastSlewRate,
|
||||
* kPORT_PassiveFilterDisable,
|
||||
* kPORT_OpenDrainDisable,
|
||||
* kPORT_LowDriveStrength,
|
||||
* kPORT_MuxAsGpio,
|
||||
* kPORT_UnlockRegister,
|
||||
* };
|
||||
* @endcode
|
||||
*
|
||||
* @param base PORT peripheral base pointer.
|
||||
* @param mask PORT pin number macro.
|
||||
* @param config PORT PCR register configuration structure.
|
||||
*/
|
||||
static inline void PORT_SetMultiplePinsConfig(PORT_Type *base, uint32_t mask, const port_pin_config_t *config)
|
||||
{
|
||||
assert(config);
|
||||
|
||||
uint16_t pcrl = *((const uint16_t *)config);
|
||||
|
||||
if (mask & 0xffffU)
|
||||
{
|
||||
base->GPCLR = ((mask & 0xffffU) << 16) | pcrl;
|
||||
}
|
||||
if (mask >> 16)
|
||||
{
|
||||
base->GPCHR = (mask & 0xffff0000U) | pcrl;
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(FSL_FEATURE_PORT_HAS_MULTIPLE_IRQ_CONFIG) && FSL_FEATURE_PORT_HAS_MULTIPLE_IRQ_CONFIG
|
||||
/*!
|
||||
* @brief Sets the port interrupt configuration in PCR register for multiple pins.
|
||||
*
|
||||
* @param base PORT peripheral base pointer.
|
||||
* @param mask PORT pin number macro.
|
||||
* @param config PORT pin interrupt configuration.
|
||||
* - #kPORT_InterruptOrDMADisabled: Interrupt/DMA request disabled.
|
||||
* - #kPORT_DMARisingEdge : DMA request on rising edge(if the DMA requests exit).
|
||||
* - #kPORT_DMAFallingEdge: DMA request on falling edge(if the DMA requests exit).
|
||||
* - #kPORT_DMAEitherEdge : DMA request on either edge(if the DMA requests exit).
|
||||
* - #kPORT_FlagRisingEdge : Flag sets on rising edge(if the Flag states exit).
|
||||
* - #kPORT_FlagFallingEdge : Flag sets on falling edge(if the Flag states exit).
|
||||
* - #kPORT_FlagEitherEdge : Flag sets on either edge(if the Flag states exit).
|
||||
* - #kPORT_InterruptLogicZero : Interrupt when logic zero.
|
||||
* - #kPORT_InterruptRisingEdge : Interrupt on rising edge.
|
||||
* - #kPORT_InterruptFallingEdge: Interrupt on falling edge.
|
||||
* - #kPORT_InterruptEitherEdge : Interrupt on either edge.
|
||||
* - #kPORT_InterruptLogicOne : Interrupt when logic one.
|
||||
* - #kPORT_ActiveHighTriggerOutputEnable : Enable active high-trigger output (if the trigger states exit).
|
||||
* - #kPORT_ActiveLowTriggerOutputEnable : Enable active low-trigger output (if the trigger states exit)..
|
||||
*/
|
||||
static inline void PORT_SetMultipleInterruptPinsConfig(PORT_Type *base, uint32_t mask, port_interrupt_t config)
|
||||
{
|
||||
assert(config);
|
||||
|
||||
if (mask & 0xffffU)
|
||||
{
|
||||
base->GICLR = (config << 16) | (mask & 0xffffU);
|
||||
}
|
||||
if (mask >> 16)
|
||||
{
|
||||
base->GICHR = (config << 16) | (mask & 0xffff0000U);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/*!
|
||||
* @brief Configures the pin muxing.
|
||||
*
|
||||
* @param base PORT peripheral base pointer.
|
||||
* @param pin PORT pin number.
|
||||
* @param mux pin muxing slot selection.
|
||||
* - #kPORT_PinDisabledOrAnalog: Pin disabled or work in analog function.
|
||||
* - #kPORT_MuxAsGpio : Set as GPIO.
|
||||
* - #kPORT_MuxAlt2 : chip-specific.
|
||||
* - #kPORT_MuxAlt3 : chip-specific.
|
||||
* - #kPORT_MuxAlt4 : chip-specific.
|
||||
* - #kPORT_MuxAlt5 : chip-specific.
|
||||
* - #kPORT_MuxAlt6 : chip-specific.
|
||||
* - #kPORT_MuxAlt7 : chip-specific.
|
||||
* @Note : This function is NOT recommended to use together with the PORT_SetPinsConfig, because
|
||||
* the PORT_SetPinsConfig need to configure the pin mux anyway (Otherwise the pin mux is
|
||||
* reset to zero : kPORT_PinDisabledOrAnalog).
|
||||
* This function is recommended to use to reset the pin mux
|
||||
*
|
||||
*/
|
||||
static inline void PORT_SetPinMux(PORT_Type *base, uint32_t pin, port_mux_t mux)
|
||||
{
|
||||
base->PCR[pin] = (base->PCR[pin] & ~PORT_PCR_MUX_MASK) | PORT_PCR_MUX(mux);
|
||||
}
|
||||
#endif /* FSL_FEATURE_PORT_PCR_MUX_WIDTH */
|
||||
|
||||
#if defined(FSL_FEATURE_PORT_HAS_DIGITAL_FILTER) && FSL_FEATURE_PORT_HAS_DIGITAL_FILTER
|
||||
|
||||
/*!
|
||||
* @brief Enables the digital filter in one port, each bit of the 32-bit register represents one pin.
|
||||
*
|
||||
* @param base PORT peripheral base pointer.
|
||||
* @param mask PORT pin number macro.
|
||||
*/
|
||||
static inline void PORT_EnablePinsDigitalFilter(PORT_Type *base, uint32_t mask, bool enable)
|
||||
{
|
||||
if (enable == true)
|
||||
{
|
||||
base->DFER |= mask;
|
||||
}
|
||||
else
|
||||
{
|
||||
base->DFER &= ~mask;
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Sets the digital filter in one port, each bit of the 32-bit register represents one pin.
|
||||
*
|
||||
* @param base PORT peripheral base pointer.
|
||||
* @param config PORT digital filter configuration structure.
|
||||
*/
|
||||
static inline void PORT_SetDigitalFilterConfig(PORT_Type *base, const port_digital_filter_config_t *config)
|
||||
{
|
||||
assert(config);
|
||||
|
||||
base->DFCR = PORT_DFCR_CS(config->clockSource);
|
||||
base->DFWR = PORT_DFWR_FILT(config->digitalFilterWidth);
|
||||
}
|
||||
|
||||
#endif /* FSL_FEATURE_PORT_HAS_DIGITAL_FILTER */
|
||||
|
||||
/*@}*/
|
||||
|
||||
/*! @name Interrupt */
|
||||
/*@{*/
|
||||
|
||||
/*!
|
||||
* @brief Configures the port pin interrupt/DMA request.
|
||||
*
|
||||
* @param base PORT peripheral base pointer.
|
||||
* @param pin PORT pin number.
|
||||
* @param config PORT pin interrupt configuration.
|
||||
* - #kPORT_InterruptOrDMADisabled: Interrupt/DMA request disabled.
|
||||
* - #kPORT_DMARisingEdge : DMA request on rising edge(if the DMA requests exit).
|
||||
* - #kPORT_DMAFallingEdge: DMA request on falling edge(if the DMA requests exit).
|
||||
* - #kPORT_DMAEitherEdge : DMA request on either edge(if the DMA requests exit).
|
||||
* - #kPORT_FlagRisingEdge : Flag sets on rising edge(if the Flag states exit).
|
||||
* - #kPORT_FlagFallingEdge : Flag sets on falling edge(if the Flag states exit).
|
||||
* - #kPORT_FlagEitherEdge : Flag sets on either edge(if the Flag states exit).
|
||||
* - #kPORT_InterruptLogicZero : Interrupt when logic zero.
|
||||
* - #kPORT_InterruptRisingEdge : Interrupt on rising edge.
|
||||
* - #kPORT_InterruptFallingEdge: Interrupt on falling edge.
|
||||
* - #kPORT_InterruptEitherEdge : Interrupt on either edge.
|
||||
* - #kPORT_InterruptLogicOne : Interrupt when logic one.
|
||||
* - #kPORT_ActiveHighTriggerOutputEnable : Enable active high-trigger output (if the trigger states exit).
|
||||
* - #kPORT_ActiveLowTriggerOutputEnable : Enable active low-trigger output (if the trigger states exit).
|
||||
*/
|
||||
static inline void PORT_SetPinInterruptConfig(PORT_Type *base, uint32_t pin, port_interrupt_t config)
|
||||
{
|
||||
base->PCR[pin] = (base->PCR[pin] & ~PORT_PCR_IRQC_MASK) | PORT_PCR_IRQC(config);
|
||||
}
|
||||
|
||||
#if defined(FSL_FEATURE_PORT_HAS_DRIVE_STRENGTH) && FSL_FEATURE_PORT_HAS_DRIVE_STRENGTH
|
||||
/*!
|
||||
* @brief Configures the port pin drive strength.
|
||||
*
|
||||
* @param base PORT peripheral base pointer.
|
||||
* @param pin PORT pin number.
|
||||
* @param config PORT pin drive strength
|
||||
* - #kPORT_LowDriveStrength = 0U - Low-drive strength is configured.
|
||||
* - #kPORT_HighDriveStrength = 1U - High-drive strength is configured.
|
||||
*/
|
||||
static inline void PORT_SetPinDriveStrength(PORT_Type* base, uint32_t pin, uint8_t strength)
|
||||
{
|
||||
base->PCR[pin] = (base->PCR[pin] & ~PORT_PCR_DSE_MASK) | PORT_PCR_DSE(strength);
|
||||
}
|
||||
#endif
|
||||
|
||||
/*!
|
||||
* @brief Reads the whole port status flag.
|
||||
*
|
||||
* If a pin is configured to generate the DMA request, the corresponding flag
|
||||
* is cleared automatically at the completion of the requested DMA transfer.
|
||||
* Otherwise, the flag remains set until a logic one is written to that flag.
|
||||
* If configured for a level sensitive interrupt that remains asserted, the flag
|
||||
* is set again immediately.
|
||||
*
|
||||
* @param base PORT peripheral base pointer.
|
||||
* @return Current port interrupt status flags, for example, 0x00010001 means the
|
||||
* pin 0 and 16 have the interrupt.
|
||||
*/
|
||||
static inline uint32_t PORT_GetPinsInterruptFlags(PORT_Type *base)
|
||||
{
|
||||
return base->ISFR;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Clears the multiple pin interrupt status flag.
|
||||
*
|
||||
* @param base PORT peripheral base pointer.
|
||||
* @param mask PORT pin number macro.
|
||||
*/
|
||||
static inline void PORT_ClearPinsInterruptFlags(PORT_Type *base, uint32_t mask)
|
||||
{
|
||||
base->ISFR = mask;
|
||||
}
|
||||
|
||||
/*@}*/
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
/*! @}*/
|
||||
|
||||
#endif /* _FSL_PORT_H_ */
|
||||
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* Copyright 2017 NXP
|
||||
* All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
/*************************************************
|
||||
File name: pin_mux
|
||||
Description:
|
||||
Others: take for references
|
||||
https://github.com/open-isa-org/open-isa.org
|
||||
History:
|
||||
1. Date: 2022-02-16
|
||||
Author: AIIT XUOS Lab
|
||||
Modification:
|
||||
*************************************************/
|
||||
|
||||
#ifndef _PIN_MUX_H_
|
||||
#define _PIN_MUX_H_
|
||||
|
||||
/*******************************************************************************
|
||||
* Definitions
|
||||
******************************************************************************/
|
||||
|
||||
/*! @brief Direction type */
|
||||
typedef enum _pin_mux_direction
|
||||
{
|
||||
kPIN_MUX_DirectionInput = 0U, /* Input direction */
|
||||
kPIN_MUX_DirectionOutput = 1U, /* Output direction */
|
||||
kPIN_MUX_DirectionInputOrOutput = 2U /* Input or output direction */
|
||||
} pin_mux_direction_t;
|
||||
|
||||
/*!
|
||||
* @addtogroup pin_mux
|
||||
* @{
|
||||
*/
|
||||
|
||||
/*******************************************************************************
|
||||
* API
|
||||
******************************************************************************/
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*!
|
||||
* @brief Calls initialization functions.
|
||||
*
|
||||
*/
|
||||
void BOARD_InitBootPins(void);
|
||||
|
||||
/*!
|
||||
* @brief Configures pin routing and optionally pin electrical features.
|
||||
*
|
||||
*/
|
||||
void BOARD_InitPins(void);
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
/*!
|
||||
* @}
|
||||
*/
|
||||
#endif /* _PIN_MUX_H_ */
|
||||
|
||||
/*******************************************************************************
|
||||
* EOF
|
||||
******************************************************************************/
|
||||
@@ -24,7 +24,7 @@
|
||||
#define LCD_HEIGHT BSP_LCD_X_MAX
|
||||
#define LCD_WIDTH BSP_LCD_Y_MAX
|
||||
|
||||
|
||||
// static uint16_t frame_buffer[LCD_HEIGHT][LCD_WIDTH];
|
||||
static uint16_t frame_buffer[LCD_HEIGHT][LCD_WIDTH] SECTION("NonCacheable.init");
|
||||
static void InitLcdifPixelClock(void)
|
||||
{
|
||||
|
||||
@@ -72,17 +72,18 @@ static int32_t GtpI2cWrite(uint8_t client_addr,uint8_t *buf,int32_t len)
|
||||
while(retries < 5)
|
||||
{
|
||||
ret = I2C_Transfer(&msg, 1);
|
||||
if (ret == 1)break;
|
||||
if (ret == 1) { break; }
|
||||
retries++;
|
||||
}
|
||||
if((retries >= 5))
|
||||
if (retries >= 5)
|
||||
{
|
||||
KPrintf("I2C Write: 0x%04X, %d bytes failed, errcode: %d! Process reset.", (((uint16_t)(buf[0] << 8)) | buf[1]), len-2, ret);
|
||||
ret = -1;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
static int32_t GtpI2cRead(uint8_t client_addr, uint8_t *buf, int32_t len)
|
||||
|
||||
static int32_t GtpI2cRead(uint8_t client_addr, uint8_t* buf, int32_t len)
|
||||
{
|
||||
struct i2c_msg msgs[2];
|
||||
int32_t ret = -1;
|
||||
@@ -100,8 +101,8 @@ static int32_t GtpI2cRead(uint8_t client_addr, uint8_t *buf, int32_t len)
|
||||
|
||||
while(retries < 5)
|
||||
{
|
||||
ret = I2C_Transfer( msgs, 2);
|
||||
if(ret == 2)break;
|
||||
ret = I2C_Transfer(msgs, 2);
|
||||
if (ret == 2)break;
|
||||
retries++;
|
||||
}
|
||||
if((retries >= 5))
|
||||
@@ -111,6 +112,7 @@ static int32_t GtpI2cRead(uint8_t client_addr, uint8_t *buf, int32_t len)
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int32_t gt91xx_Config_Write_Proc()
|
||||
{
|
||||
int32_t ret = -1;
|
||||
@@ -154,8 +156,12 @@ static int32_t gt91xx_Config_Write_Proc()
|
||||
*/
|
||||
bool GetTouchEvent(POINT *touch_point,touch_event_t *touch_event)
|
||||
{
|
||||
|
||||
uint8_t end_cmd[3] = {GTP_READ_COOR_ADDR >> 8, GTP_READ_COOR_ADDR & 0xFF, 0};
|
||||
if (touch_point == NULL || touch_event == NULL) {
|
||||
KPrintf("error: touch event error params.\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
uint8_t end_cmd[3] = { GTP_READ_COOR_ADDR >> 8, GTP_READ_COOR_ADDR & 0xFF, 0 };
|
||||
uint8_t point_data[2 + 1 + 8 * GTP_MAX_TOUCH + 1]={GTP_READ_COOR_ADDR >> 8, GTP_READ_COOR_ADDR & 0xFF};
|
||||
uint8_t touch_num = 0;
|
||||
uint8_t finger = 0;
|
||||
@@ -168,7 +174,7 @@ bool GetTouchEvent(POINT *touch_point,touch_event_t *touch_event)
|
||||
int32_t input_w = 0;
|
||||
|
||||
int32_t ret = -1;
|
||||
|
||||
|
||||
ret = GtpI2cRead(client_addr, point_data, 12);//10字节寄存器加2字节地址
|
||||
if (ret < 0)
|
||||
{
|
||||
@@ -217,7 +223,7 @@ bool GetTouchEvent(POINT *touch_point,touch_event_t *touch_event)
|
||||
Pre_Touch_Point.Y = -1;
|
||||
}
|
||||
pre_touch = touch_num;
|
||||
|
||||
|
||||
exit_work_func:
|
||||
{
|
||||
ret = GtpI2cWrite(client_addr, end_cmd, 3);
|
||||
|
||||
@@ -32,42 +32,43 @@ lpi2c_master_handle_t g_m_handle;
|
||||
volatile bool g_MasterCompletionFlag = false;
|
||||
volatile bool g_TouchPadInputSignal = false;
|
||||
volatile bool SemReleaseFlag = false;
|
||||
uint32_t i2c_lockup_cnt = 0;
|
||||
/*******************************************************************************
|
||||
* Code
|
||||
******************************************************************************/
|
||||
|
||||
/**
|
||||
* @brief 对GT91xx芯片进行复位
|
||||
* @param 无
|
||||
* @retval 无
|
||||
* @brief ��GT91xxоƬ���и�λ
|
||||
* @param ��
|
||||
* @retval ��
|
||||
*/
|
||||
void GTP_ResetChip(void)
|
||||
{
|
||||
/* 先把RST INT配置为输出模式 */
|
||||
/* �Ȱ�RST INT����Ϊ���ģʽ */
|
||||
gpio_pin_config_t rst_int_config = {kGPIO_DigitalOutput, 0, kGPIO_NoIntmode};
|
||||
|
||||
GPIO_PinInit(TOUCH_PAD_INT_GPIO, TOUCH_PAD_INT_GPIO_PIN, &rst_int_config);
|
||||
|
||||
/*初始化GT9157,INT为低电平,则gt9157的设备地址被配置为0xBA*/
|
||||
/*��ʼ��GT9157,INTΪ�͵�ƽ����gt9157���豸��ַ������Ϊ0xBA*/
|
||||
|
||||
/*复位为低电平,为初始化做准备*/
|
||||
/*��λΪ�͵�ƽ��Ϊ��ʼ������*/
|
||||
GPIO_PinWrite(TOUCH_PAD_INT_GPIO, TOUCH_PAD_INT_GPIO_PIN, 0U);
|
||||
|
||||
//INT配置成中断输入
|
||||
//INT���ó��ж�����
|
||||
rst_int_config.direction = kGPIO_DigitalInput;
|
||||
rst_int_config.outputLogic = 0;
|
||||
rst_int_config.interruptMode = kGPIO_IntFallingEdge;
|
||||
|
||||
GPIO_PinInit(TOUCH_PAD_INT_GPIO, TOUCH_PAD_INT_GPIO_PIN, &rst_int_config);
|
||||
|
||||
/* 使能引脚中断 */
|
||||
/* ʹ�������ж� */
|
||||
GPIO_PortEnableInterrupts(TOUCH_PAD_INT_GPIO, 1U << TOUCH_PAD_INT_GPIO_PIN);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 禁止触摸芯片的中断
|
||||
* @param 无
|
||||
* @retval 无
|
||||
* @brief ��ֹ����оƬ���ж�
|
||||
* @param ��
|
||||
* @retval ��
|
||||
*/
|
||||
void GTP_IRQDisable(void)
|
||||
{
|
||||
@@ -75,9 +76,9 @@ void GTP_IRQDisable(void)
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 使能触摸芯片的中断
|
||||
* @param 无
|
||||
* @retval 无
|
||||
* @brief ʹ�ܴ���оƬ���ж�
|
||||
* @param ��
|
||||
* @retval ��
|
||||
*/
|
||||
void GTP_IRQEnable(void)
|
||||
{
|
||||
@@ -93,25 +94,25 @@ void GTP_IRQEnable(void)
|
||||
|
||||
gpio_pin_config_t rst_int_config;
|
||||
|
||||
//INT配置成中断输入
|
||||
//INT���ó��ж�����
|
||||
rst_int_config.direction = kGPIO_DigitalInput;
|
||||
rst_int_config.outputLogic = 0;
|
||||
rst_int_config.interruptMode = kGPIO_IntFallingEdge;
|
||||
|
||||
GPIO_PinInit(TOUCH_PAD_INT_GPIO, TOUCH_PAD_INT_GPIO_PIN, &rst_int_config);
|
||||
|
||||
/* 使能引脚中断 */
|
||||
/* ʹ�������ж� */
|
||||
GPIO_PortEnableInterrupts(TOUCH_PAD_INT_GPIO, 1U << TOUCH_PAD_INT_GPIO_PIN);
|
||||
|
||||
/* 使能中断IRQ */
|
||||
/* ʹ���ж�IRQ */
|
||||
EnableIRQ(GT9xx_PEN_IRQ);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief 初始化触摸芯片使用的I2C外设
|
||||
* @param 无
|
||||
* @retval 无
|
||||
* @brief ��ʼ������оƬʹ�õ�I2C����
|
||||
* @param ��
|
||||
* @retval ��
|
||||
*/
|
||||
void GTP_I2C_ModeInit(void)
|
||||
{
|
||||
@@ -142,25 +143,56 @@ void GtpI2cDeinit(void)
|
||||
LPI2C_MasterDeinit(GTP_I2C_MASTER);
|
||||
}
|
||||
|
||||
void I2CLockupRecover(void) {
|
||||
IOMUXC_SetPinMux(TOUCH_PAD_RECOVER_SCL_IOMUXC, 0U);
|
||||
IOMUXC_SetPinMux(TOUCH_PAD_RECOVER_SDA_IOMUXC, 0U);
|
||||
|
||||
const gpio_pin_config_t rec_pin_config = {
|
||||
.direction = kGPIO_DigitalOutput,
|
||||
.outputLogic = 1U,
|
||||
};
|
||||
|
||||
GPIO_PinInit(TOUCH_PAD_RECOVER_SCL_GPIO, TOUCH_PAD_RECOVER_SCL_GPIO_PIN, &rec_pin_config);
|
||||
GPIO_PinInit(TOUCH_PAD_RECOVER_SDA_GPIO, TOUCH_PAD_RECOVER_SDA_GPIO_PIN, &rec_pin_config);
|
||||
|
||||
uint32_t primask = DisableGlobalIRQ();
|
||||
// recover scl
|
||||
for (uint32_t i = 0; i < 0xfffff; ++i) {}
|
||||
for (uint32_t i = 0U; i < I2C_RECOVER_NUM_CLOCKS; ++i) {
|
||||
for (uint32_t i = 0; i < 0xfffff; ++i) {}
|
||||
GPIO_PinWrite(TOUCH_PAD_RECOVER_SCL_GPIO, TOUCH_PAD_RECOVER_SCL_GPIO_PIN, 0U);
|
||||
for (uint32_t i = 0; i < 0xfffff; ++i) {}
|
||||
GPIO_PinWrite(TOUCH_PAD_RECOVER_SCL_GPIO, TOUCH_PAD_RECOVER_SCL_GPIO_PIN, 1U);
|
||||
}
|
||||
GPIO_PinWrite(TOUCH_PAD_RECOVER_SDA_GPIO, TOUCH_PAD_RECOVER_SDA_GPIO_PIN, 1U);
|
||||
EnableGlobalIRQ(primask);
|
||||
|
||||
// reset pin to scl
|
||||
IOMUXC_SetPinMux(IOMUXC_GPIO_AD_B1_00_LPI2C1_SCL, 1U);
|
||||
IOMUXC_SetPinConfig(IOMUXC_GPIO_AD_B1_00_LPI2C1_SCL, 0xD8B0u);
|
||||
IOMUXC_SetPinMux(IOMUXC_GPIO_AD_B1_01_LPI2C1_SDA, 1U);
|
||||
IOMUXC_SetPinConfig(IOMUXC_GPIO_AD_B1_01_LPI2C1_SDA, 0xD8B0u);
|
||||
|
||||
i2c_lockup_cnt = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 使用IIC读取数据
|
||||
* @brief ʹ��IIC��ȡ����
|
||||
* @param
|
||||
* @arg ClientAddr:从设备地址
|
||||
* @arg pBuffer:存放由从机读取的数据的缓冲区指针
|
||||
* @arg NumByteToRead:读取的数据长度
|
||||
* @retval 无
|
||||
* @arg ClientAddr:���豸��ַ
|
||||
* @arg pBuffer:����ɴӻ���ȡ�����ݵĻ�����ָ��
|
||||
* @arg NumByteToRead:��ȡ�����ݳ���
|
||||
* @retval ��
|
||||
*/
|
||||
uint32_t I2C_ReadBytes(uint8_t ClientAddr,uint8_t* pBuffer, uint16_t NumByteToRead)
|
||||
{
|
||||
lpi2c_master_transfer_t masterXfer = {0};
|
||||
lpi2c_master_transfer_t masterXfer = { 0 };
|
||||
status_t reVal = kStatus_Fail;
|
||||
uint32_t i2c_timeout = I2CT_LONG_TIMEOUT;
|
||||
|
||||
|
||||
/* subAddress = 0x00, data = pBuffer 自从机处接收
|
||||
起始信号start + 设备地址slaveaddress(w 写方向) + 子地址subAddress +
|
||||
重复起始信号repeated start + 设备地址slaveaddress(r 读方向) +
|
||||
接收缓冲数据rx data buffer + 停止信号stop */
|
||||
/* subAddress = 0x00, data = pBuffer �Դӻ�������
|
||||
��ʼ�ź�start + �豸��ַslaveaddress(w д����) + �ӵ�ַsubAddress +
|
||||
�ظ���ʼ�ź�repeated start + �豸��ַslaveaddress(r ������) +
|
||||
���ջ�������rx data buffer + ֹͣ�ź�stop */
|
||||
masterXfer.slaveAddress = (ClientAddr>>1);
|
||||
masterXfer.direction = kLPI2C_Read;
|
||||
masterXfer.subaddress = (uint32_t)0;
|
||||
@@ -169,47 +201,44 @@ uint32_t I2C_ReadBytes(uint8_t ClientAddr,uint8_t* pBuffer, uint16_t NumByteToRe
|
||||
masterXfer.dataSize = NumByteToRead;
|
||||
masterXfer.flags = kLPI2C_TransferDefaultFlag;
|
||||
|
||||
/* 复位传输完成标志 */
|
||||
/* ��λ������ɱ�־ */
|
||||
g_MasterCompletionFlag = false;
|
||||
|
||||
reVal = LPI2C_MasterTransferNonBlocking(GTP_I2C_MASTER, &g_m_handle, &masterXfer);
|
||||
if (reVal != kStatus_Success)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* 等待传输完成 */
|
||||
/* �ȴ�������� */
|
||||
while (!g_MasterCompletionFlag)
|
||||
{
|
||||
if((i2c_timeout--) == 0)
|
||||
if ((i2c_timeout--) == 0)
|
||||
return I2C_Timeout_Callback(0);
|
||||
}
|
||||
|
||||
g_MasterCompletionFlag = false;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 使用IIC写入数据
|
||||
* @brief ʹ��IICд������
|
||||
* @param
|
||||
* @arg ClientAddr:从设备地址
|
||||
* @arg pBuffer:缓冲区指针
|
||||
* @arg NumByteToWrite:写的字节数
|
||||
* @retval 无
|
||||
* @arg ClientAddr:���豸��ַ
|
||||
* @arg pBuffer:������ָ��
|
||||
* @arg NumByteToWrite:д���ֽ���
|
||||
* @retval ��
|
||||
*/
|
||||
uint32_t I2C_WriteBytes(uint8_t ClientAddr,uint8_t* pBuffer, uint8_t NumByteToWrite)
|
||||
{
|
||||
lpi2c_master_transfer_t masterXfer = {0};
|
||||
lpi2c_master_transfer_t masterXfer = { 0 };
|
||||
status_t reVal = kStatus_Fail;
|
||||
uint32_t i2c_timeout = I2CT_LONG_TIMEOUT;
|
||||
|
||||
|
||||
/* subAddress = 0x00, data = pBuffer 发送至从机
|
||||
起始信号start + 设备地址slaveaddress(w 写方向) +
|
||||
发送缓冲数据tx data buffer + 停止信号stop */
|
||||
|
||||
masterXfer.slaveAddress = (ClientAddr>>1);
|
||||
/* subAddress = 0x00, data = pBuffer �������ӻ�
|
||||
��ʼ�ź�start + �豸��ַslaveaddress(w д����) +
|
||||
���ͻ�������tx data buffer + ֹͣ�ź�stop */
|
||||
|
||||
masterXfer.slaveAddress = (ClientAddr >> 1);
|
||||
masterXfer.direction = kLPI2C_Write;
|
||||
masterXfer.subaddress = (uint32_t)0;
|
||||
masterXfer.subaddressSize = 0;
|
||||
@@ -217,90 +246,97 @@ uint32_t I2C_WriteBytes(uint8_t ClientAddr,uint8_t* pBuffer, uint8_t NumByteToW
|
||||
masterXfer.dataSize = NumByteToWrite;
|
||||
masterXfer.flags = kLPI2C_TransferDefaultFlag;
|
||||
|
||||
/* 复位传输完成标志 */
|
||||
/* ��λ������ɱ�־ */
|
||||
g_MasterCompletionFlag = false;
|
||||
|
||||
reVal = LPI2C_MasterTransferNonBlocking(GTP_I2C_MASTER, &g_m_handle, &masterXfer);
|
||||
if (reVal != kStatus_Success)
|
||||
{
|
||||
// handle hangs
|
||||
i2c_lockup_cnt++;
|
||||
if (i2c_lockup_cnt >= I2C_BUSY_LIMIT) {
|
||||
I2CLockupRecover();
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* 等待传输完成 */
|
||||
/* �ȴ�������� */
|
||||
while (!g_MasterCompletionFlag)
|
||||
{
|
||||
if((i2c_timeout--) == 0)
|
||||
return I2C_Timeout_Callback(1);
|
||||
}
|
||||
g_MasterCompletionFlag = false;
|
||||
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief IIC等待超时调用本函数输出调试信息
|
||||
* @brief IIC�ȴ���ʱ���ñ��������������Ϣ
|
||||
* @param None.
|
||||
* @retval 返回0xff,表示IIC读取数据失败
|
||||
* @retval ����0xff����ʾIIC��ȡ����ʧ��
|
||||
*/
|
||||
static uint32_t I2C_Timeout_Callback(uint8_t errorCode)
|
||||
{
|
||||
/* Block communication and all processes */
|
||||
KPrintf("I2C timeout!errorCode = %d\n",errorCode);
|
||||
// KPrintf("I2C timeout!errorCode = %d\n",errorCode);
|
||||
|
||||
return 0xFF;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief I2C外设传输完成的回调函数
|
||||
* @param 无
|
||||
* @retval 无
|
||||
* @brief I2C���贫����ɵĻص�����
|
||||
* @param ��
|
||||
* @retval ��
|
||||
*/
|
||||
static void I2C_Master_Callback(LPI2C_Type *base, lpi2c_master_handle_t *handle, status_t status, void *userData)
|
||||
{
|
||||
/* 接收到kStatus_Success标志后,
|
||||
设置g_MasterCompletionFlag标志表明传输成功 */
|
||||
if (status == kStatus_Success)
|
||||
{
|
||||
/* ���յ�kStatus_Success��־��
|
||||
����g_MasterCompletionFlag��־��������ɹ� */
|
||||
if (status != kStatus_LPI2C_Nak) {
|
||||
g_MasterCompletionFlag = true;
|
||||
/* Display failure information when status is not success. */
|
||||
if (status != kStatus_Success)
|
||||
{
|
||||
// KPrintf("Error occured during transfer!.\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief 触摸引脚及芯片初始化
|
||||
* @param 无
|
||||
* @retval 无
|
||||
* @brief �������ż�оƬ��ʼ��
|
||||
* @param ��
|
||||
* @retval ��
|
||||
*/
|
||||
void I2C_Touch_Init(void)
|
||||
{
|
||||
|
||||
// /* 初始化I2C外设工作模式 */
|
||||
// /* ��ʼ��I2C���蹤��ģʽ */
|
||||
GTP_I2C_ModeInit();
|
||||
|
||||
/* 复位触摸芯片,配置地址 */
|
||||
/* ��λ����оƬ�����õ�ַ */
|
||||
GTP_ResetChip();
|
||||
}
|
||||
|
||||
|
||||
/***************************中断相关******************************/
|
||||
/***************************����******************************/
|
||||
/**
|
||||
* @brief 触摸芯片TOUCH_PAD_INT_GPIO_PIN引脚的中断服务函数
|
||||
* @param 无
|
||||
* @retval 无
|
||||
* @brief ����оƬTOUCH_PAD_INT_GPIO_PIN���ŵ��жϷ�����
|
||||
* @param ��
|
||||
* @retval ��
|
||||
*/
|
||||
//void TOUCH_PAD_IRQHANDLER(void)
|
||||
extern int touch_sem;
|
||||
void GT9xx_PEN_IRQHandler(int irqn, void *arg)
|
||||
{
|
||||
DisableIRQ(GT9xx_PEN_IRQ);
|
||||
/* 确认是触摸芯片的中断 */
|
||||
/* ȷ���Ǵ���оƬ���ж� */
|
||||
if(GPIO_GetPinsInterruptFlags(TOUCH_PAD_INT_GPIO) & 1U << TOUCH_PAD_INT_GPIO_PIN)
|
||||
{
|
||||
/* 清除中断标志 */
|
||||
/* ����жϱ�־ */
|
||||
GPIO_PortClearInterruptFlags(TOUCH_PAD_INT_GPIO, 1U << TOUCH_PAD_INT_GPIO_PIN);
|
||||
/* 切换触摸输入状态标志 */
|
||||
/* �л���������״̬��־ */
|
||||
g_TouchPadInputSignal = true;
|
||||
if(!SemReleaseFlag)
|
||||
{
|
||||
@@ -322,7 +358,7 @@ DECLARE_HW_IRQ(GT9xx_PEN_IRQ, GT9xx_PEN_IRQHandler, NONE);
|
||||
* terminate the operation; each message begins with a START.
|
||||
* @num: Number of messages to be executed.
|
||||
*/
|
||||
int I2C_Transfer( struct i2c_msg *msgs,int num)
|
||||
int I2C_Transfer(struct i2c_msg* msgs, int num)
|
||||
{
|
||||
int im = 0;
|
||||
int ret = 0;
|
||||
@@ -331,19 +367,19 @@ int I2C_Transfer( struct i2c_msg *msgs,int num)
|
||||
|
||||
for (im = 0; ret == 0 && im != num; im++)
|
||||
{
|
||||
if ((msgs[im].flags&I2C_M_RD)) //根据flag判断是读数据还是写数据
|
||||
if (msgs[im].flags & I2C_M_RD) //����flag�ж��Ƕ����ݻ���д����
|
||||
{
|
||||
ret = I2C_ReadBytes(msgs[im].addr, msgs[im].buf, msgs[im].len); //IIC读取数据
|
||||
ret = I2C_ReadBytes(msgs[im].addr, msgs[im].buf, msgs[im].len); //IIC��ȡ����
|
||||
} else
|
||||
{
|
||||
ret = I2C_WriteBytes(msgs[im].addr, msgs[im].buf, msgs[im].len); //IIC写入数据
|
||||
ret = I2C_WriteBytes(msgs[im].addr, msgs[im].buf, msgs[im].len); //IIC�����
|
||||
}
|
||||
}
|
||||
|
||||
if(ret)
|
||||
return ret;
|
||||
|
||||
return im; //正常完成的传输结构个数
|
||||
return im; //������ɵĴ���ṹ����
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -26,12 +26,13 @@ extern volatile bool SemReleaseFlag;
|
||||
|
||||
#define GTP_I2C_BAUDRATE 400000U
|
||||
|
||||
/* 等待超时时间 */
|
||||
/* �ȴ���ʱʱ�� */
|
||||
#define I2CT_FLAG_TIMEOUT ((uint32_t)0x10000)
|
||||
#define I2CT_LONG_TIMEOUT ((uint32_t)(10 * I2CT_FLAG_TIMEOUT))
|
||||
|
||||
#define I2C_BUSY_LIMIT 5
|
||||
|
||||
/*! @brief 触摸芯片引脚定义 */
|
||||
/*! @brief ����оƬ���Ŷ��� */
|
||||
|
||||
#define TOUCH_PAD_SCL_IOMUXC IOMUXC_GPIO_AD_B1_00_LPI2C1_SCL
|
||||
#define TOUCH_PAD_SDA_IOMUXC IOMUXC_GPIO_AD_B1_01_LPI2C1_SDA
|
||||
@@ -48,9 +49,18 @@ extern volatile bool SemReleaseFlag;
|
||||
#define GT9xx_PEN_IRQ GPIO2_Combined_16_31_IRQn
|
||||
#define GT9xx_PEN_IRQHandler GPIO2_Combined_16_31_IRQHandler
|
||||
|
||||
#define TOUCH_PAD_RECOVER_SCL_GPIO GPIO1
|
||||
#define TOUCH_PAD_RECOVER_SCL_GPIO_PIN (16U)
|
||||
#define TOUCH_PAD_RECOVER_SDA_GPIO GPIO1
|
||||
#define TOUCH_PAD_RECOVER_SDA_GPIO_PIN (17U)
|
||||
#define TOUCH_PAD_RECOVER_SCL_IOMUXC IOMUXC_GPIO_AD_B1_00_GPIO1_IO16
|
||||
#define TOUCH_PAD_RECOVER_SDA_IOMUXC IOMUXC_GPIO_AD_B1_01_GPIO1_IO17
|
||||
|
||||
#define I2C_RECOVER_NUM_CLOCKS 10U /* # clock cycles for recovery */
|
||||
#define I2C_RECOVER_CLOCK_FREQ 50000U /* clock frequency for recovery */
|
||||
|
||||
|
||||
//函数接口
|
||||
//�����ӿ�
|
||||
int32_t GTP_I2C_ReadBytes(uint8_t client_addr, uint8_t *buf, int32_t len);
|
||||
|
||||
void I2C_Touch_Init(void);
|
||||
|
||||
@@ -7,8 +7,8 @@
|
||||
* @date 2022-04-25
|
||||
*/
|
||||
|
||||
#ifndef CONNECT_TOUCH_H
|
||||
#define CONNECT_TOUCH_H
|
||||
#ifndef __CONNECT_TOUCH_H__
|
||||
#define __CONNECT_TOUCH_H__
|
||||
|
||||
#include <device.h>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user