/*
 * __________________________________________________________________
 *
 * Copyright (C) [2023] by InvenSense, Inc.
 * 
 * Permission to use, copy, modify, and/or distribute this software
 * for any purpose with or without fee is hereby granted.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
 * WARRANTIES  WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
 * WARRANTIES OF MERCHANTABILITY  AND FITNESS. IN NO EVENT SHALL
 * THE AUTHOR BE LIABLE  FOR ANY SPECIAL, DIRECT, INDIRECT, OR
 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
 * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 * __________________________________________________________________
 */

/** @defgroup GPIO GPIO
 *  @ingroup  Low_Level_Driver
 *  @{
 */
#ifndef _INV_GPIO_H_
#define _INV_GPIO_H_

#ifdef __cplusplus
extern "C" {
#endif

enum gpio_inv_pin_num {
	INV_GPIO_INT1 = 0,         /* Connected to the INT1 pin of the Invensense chip. */
	INV_GPIO_INT2,             /* Connected to the INT2 pin of the Invensense chip. */
	INV_GPIO_FSYNC,            /* Connected to the FSYNC pin of the Invensense chip. */
	INV_GPIO_3RD_PARTY_INT1,   /* Connected to the interrupt pin of the 3rd party chip. */
	INV_GPIO_SW0_BUTTON,       /* Connected to the SW0 button. */
	INV_GPIO_CLKIN,            /* Output SLCK on PA17 pin. Set a hardawre bridge to connect to CLKIN pin of the Invensense chip. */
	INV_GPIO_MAX
};

/** @brief Init the GPIO to output
 *  @param[in] pin_num to define which pin to configure
 */
void inv_gpio_init_pin_out(unsigned pin_num);

/** @brief Toggle GPIO state
 *  @param[in] pin_num which GPIO pin shall be toggled
 */
void inv_gpio_toggle_pin(unsigned pin_num);

/** @brief Get GPIO state
 *  @param[in]	pin_num which GPIO pin to read status
 *  @return		Pin status, -1 in case of pin number error
 */
int inv_gpio_get_status(unsigned pin_num);

/** @brief Output 32kHz clock (SLCK) to dedicated GPIO (PA17)
 *  @param[in]	pin_num which GPIO pin to output clock
 *  @warning This is not compatible with any call to gpio_sensor_irq_init(TO_MASK(GPIO_SENSOR_IRQ_D7))
 */
int inv_gpio_output_clk_on_pin(unsigned pin_num);

/** @brief Init the sensor line interrupt to wake-up the MCU
 *  @param[in]	int_num         IRQ pin as defined by enum gpio_sensor_irq_num
 *  @param[in]	interrupt_cb    callback to call on interrupt
 *  @param[in]	context         context passed to callback
 */
void inv_gpio_sensor_irq_init(unsigned pin_num,
		void (*interrupt_cb)(void * context, unsigned int_num), void * context);

#ifdef __cplusplus
}
#endif

#endif /* _INV_GPIO_H_ */

/** @} */
