From 3061ecca3d0fdfb87dabbf5f63c9e06c2a30f53a Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Thu, 23 Aug 2018 17:08:59 +0200 Subject: o Initial import. --- .../components/drivers_ext/adns2080/adns2080.c | 358 +++++++++++++++++++++ .../components/drivers_ext/adns2080/adns2080.h | 317 ++++++++++++++++++ 2 files changed, 675 insertions(+) create mode 100644 thirdparty/nRF5_SDK_15.0.0_a53641a/components/drivers_ext/adns2080/adns2080.c create mode 100644 thirdparty/nRF5_SDK_15.0.0_a53641a/components/drivers_ext/adns2080/adns2080.h (limited to 'thirdparty/nRF5_SDK_15.0.0_a53641a/components/drivers_ext/adns2080') diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/drivers_ext/adns2080/adns2080.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/drivers_ext/adns2080/adns2080.c new file mode 100644 index 0000000..6b30f11 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/drivers_ext/adns2080/adns2080.c @@ -0,0 +1,358 @@ +/** + * Copyright (c) 2009 - 2018, Nordic Semiconductor ASA + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 3. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 4. This software, with or without modification, must only be used with a + * Nordic Semiconductor ASA integrated circuit. + * + * 5. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +#include +#include + +#include "adns2080.h" +#include "sdio.h" + +/*lint ++flb "Enter library region" */ + +#define ADNS2080_PRODUCT_ID (0x2AU) /*!< ADNS2080 product id */ +#define ADNS2080_RESET_NUMBER (0x5AU) /*!< ADNS2080 reset code */ + +/* ADNS2080 register addresses */ +#define REG_PROD_ID (0x00U) /*!< Product ID. Default value : 0x2A */ +#define REG_REV_ID (0x01U) /*!< Revision ID. Default value : 0x00 */ +#define REG_MOTION_ST (0x02U) /*!< Motion Status. Default value : 0x00 */ +#define REG_DELTA_X (0x03U) /*!< Lower byte of Delta_X. Default value : 0x00 */ +#define REG_DELTA_Y (0x04U) /*!< Lower byte of Delta_Y. Default value : 0x00 */ +#define REG_SQUAL (0x05U) /*!< Squal Quality. Default value : 0x00 */ +#define REG_SHUT_HI (0x06U) /*!< Shutter Open Time (Upper 8-bit). Default value : 0x00 */ +#define REG_SHUT_LO (0x07U) /*!< Shutter Open Time (Lower 8-bit). Default value : 0x64 */ +#define REG_PIX_MAX (0x08U) /*!< Maximum Pixel Value. Default value : 0xD0 */ +#define REG_PIX_ACCUM (0x09U) /*!< Average Pixel Value. Default value : 0x80 */ +#define REG_PIX_MIN (0x0AU) /*!< Minimum Pixel Value. Default value : 0x00 */ +#define REG_PIX_GRAB (0x0BU) /*!< Pixel Grabber. Default value : 0x00 */ +#define REG_DELTA_XY_HIGH (0x0CU) /*!< Upper 4 bits of Delta X and Y displacement. Default value : 0x00 */ +#define REG_MOUSE_CTRL (0x0DU) /*!< Mouse Control. Default value : 0x01 */ +#define REG_RUN_DOWNSHIFT (0x0EU) /*!< Run to Rest1 Time. Default value : 0x08 */ +#define REG_REST1_PERIOD (0x0FU) /*!< Rest1 Period. Default value : 0x01 */ +#define REG_REST1_DOWNSHIFT (0x10U) /*!< Rest1 to Rest2 Time. Default value : 0x1f */ +#define REG_REST2_PERIOD (0x11U) /*!< Rest2 Period. Default value : 0x09 */ +#define REG_REST2_DOWNSHIFT (0x12U) /*!< Rest2 to Rest3 Time. Default value : 0x2f */ +#define REG_REST3_PERIOD (0x13U) /*!< Rest3 Period. Default value : 0x31 */ +#define REG_PERFORMANCE (0x22U) /*!< Performance. Default value : 0x00 */ +#define REG_RESET (0x3aU) /*!< Reset. Default value : 0x00 */ +#define REG_NOT_REV_ID (0x3fU) /*!< Inverted Revision ID. Default value : 0xff */ +#define REG_LED_CTRL (0x40U) /*!< LED Control. Default value : 0x00 */ +#define REG_MOTION_CTRL (0x41U) /*!< Motion Control. Default value : 0x40 */ +#define REG_BURST_READ_FIRST (0x42U) /*!< Burst Read Starting Register. Default value : 0x03 */ +#define REG_BURST_READ_LAST (0x44U) /*!< Burst Read Ending Register. Default value : 0x09 */ +#define REG_REST_MODE_CONFIG (0x45U) /*!< Rest Mode Confi guration. Default value : 0x00 */ +#define REG_MOTION_BURST (0x63U) /*!< Burst Read. Default value : 0x00 */ + +/* ADNS2080 register bits */ +#define REG_MOUSE_CTRL_POWERDOWN (0x02U) /*!< Mouse control register powerdown bit */ +#define REG_MOTION_CTRL_MOT_A (0x80U) /*!< Motion control register polarity bit */ +#define REG_MOTION_CTRL_MOT_S (0x40U) /*!< Motion control register edge sensitivity bit */ +#define REG_MOUSE_CTRL_RES_EN (0x40U) /*!< Mouse control register resolution enable bit */ +#define REG_MOUSE_CTRL_BIT_REPORTING (0x80U) /*!< Mouse control register "number of motion bits" bit*/ + +void adns2080_movement_read(int16_t * deltaX, int16_t * deltaY) +{ + uint8_t delta_x; /*!< Stores REG_DELTA_X contents */ + uint8_t delta_y; /*!< Stores REG_DELTA_Y contents */ + uint8_t delta_xy_high; /*!< Stores REG_DELTA_XY contents which contains upper 4 bits for both delta_x and delta_y when 12 bit mode is used */ + uint8_t delta_x_high; /*!< Stores delta_x 4 MSB bits */ + uint8_t delta_y_high; /*!< Stores delta_y 4 MSB bits */ + + uint16_t u16_deltaX; /*!< This is used to buffer the result and will be cast later to int16_t */ + uint16_t u16_deltaY; /*!< This is used to buffer the result and will be cast later to int16_t */ + + delta_x = sdio_read_byte(REG_DELTA_X); + delta_y = sdio_read_byte(REG_DELTA_Y); + + if (adns2080_motion_bits_read() == ADNS2080_MOTION_BITS_12) + { + // In 12 bit mode the upper 4 bits are stored in a separate register + // where first 4 upper bits are for delta_x and lower 4 bits for delta_y. + delta_xy_high = sdio_read_byte(REG_DELTA_XY_HIGH); + + delta_x_high = ((delta_xy_high & 0xF0) >> 4); + delta_y_high = (delta_xy_high & 0x0F); + + // Check if MSB is 1. If it is, this is a negative number and we have + // to fill the upper unused bits with 1s. + if (delta_x_high & 0x08) + { + u16_deltaX = 0xF000; + } + else + { + u16_deltaX = 0x0000; + } + + // Check if MSB is 1. If it is, this is a negative number and we have + // to fill the upper unused bits with 1s. + if (delta_y_high & 0x08) + { + u16_deltaY = 0xF000; + } + else + { + u16_deltaY = 0x0000; + } + + u16_deltaX |= (delta_x_high << 4) | delta_x; + u16_deltaY |= (delta_y_high << 4) | delta_y; + } + else // Only 8 bits is used for motion data + { + // Check if MSB is 1. If it is, this is a negative number and we have + // to fill the upper unused bits with 1s. + if (delta_x & 0x80) + { + u16_deltaX = 0xFF00; + } + else + { + u16_deltaX = 0x0000; + } + + // Check if MSB is 1. If it is, this is a negative number and we have + // to fill the upper unused bits with 1s. + if (delta_y & 0x80) + { + u16_deltaY = 0xFF00; + } + else + { + u16_deltaY = 0x0000; + } + + u16_deltaX |= delta_x; + u16_deltaY |= delta_y; + } + + *deltaX = (int16_t)u16_deltaX; + *deltaY = (int16_t)u16_deltaY; +} + +adns2080_motion_bits_t adns2080_motion_bits_read(void) +{ + /* Read the most significant bit */ + return (adns2080_motion_bits_t)((sdio_read_byte(REG_MOUSE_CTRL) >> 7) & 0x01); +} + +bool adns2080_is_motion_detected(void) +{ + return ((sdio_read_byte(REG_MOTION_ST) & 0x80) != 0); +} + +uint8_t adns2080_product_id_read(void) +{ + return sdio_read_byte(REG_PROD_ID); +} + +uint8_t adns2080_revision_id_read(void) +{ + return sdio_read_byte(REG_REV_ID); +} + +adns2080_status_t adns2080_init(void) +{ + sdio_init(); + adns2080_reset(); + + if (adns2080_product_id_read() != ADNS2080_PRODUCT_ID) + { + return ADNS2080_CHIP_NOT_DETECTED; + } + + sdio_write_byte(REG_BURST_READ_FIRST, REG_DELTA_X); + sdio_write_byte(REG_BURST_READ_LAST, REG_DELTA_Y); + + return ADNS2080_OK; +} + +void adns2080_reset(void) +{ + sdio_write_byte(REG_RESET, ADNS2080_RESET_NUMBER); +} + +void adns2080_powerdown(void) +{ + sdio_write_byte(REG_MOUSE_CTRL, REG_MOUSE_CTRL_POWERDOWN); +} + +void adns2080_wakeup(void) +{ + adns2080_reset(); +} + +adns2080_status_t adns2080_motion_interrupt_set(motion_output_polarity_t polarity, motion_output_sensitivity_t sensitivity) +{ + uint8_t databyte = 0; + adns2080_status_t status = ADNS2080_OK; + + switch (polarity) + { + case ADNS2080_MOTION_OUTPUT_POLARITY_LOW: + databyte = 0; // Clear REG_MOTION_CTRL_MOT_A bit + break; + + case ADNS2080_MOTION_OUTPUT_POLARITY_HIGH: + databyte = REG_MOTION_CTRL_MOT_A; + break; + + default: + status = ADNS2080_INVALID_PARAMETER; + break; + } + + switch (sensitivity) + { + case ADNS2080_MOTION_OUTPUT_SENSITIVITY_LEVEL: + databyte &= ~(REG_MOTION_CTRL_MOT_S); + break; + + case ADNS2080_MOTION_OUTPUT_SENSITIVITY_EDGE: + databyte |= (REG_MOTION_CTRL_MOT_S); + break; + + default: + status = ADNS2080_INVALID_PARAMETER; + break; + } + + if (status == ADNS2080_OK) + { + sdio_write_byte(REG_MOTION_CTRL, databyte); + } + + return status; +} + +adns2080_status_t adns2080_resolution_set(adns2080_resolution_t resolution) +{ + uint8_t databyte = sdio_read_byte(REG_MOUSE_CTRL); + adns2080_status_t status = ADNS2080_OK; + + // Enable resolution settings on REG_MOUSE_CTRL [4:2] + databyte |= (REG_MOUSE_CTRL_RES_EN); + + switch (resolution) + { + case ADNS2080_RESOLUTION_250DPI: + case ADNS2080_RESOLUTION_500DPI: + case ADNS2080_RESOLUTION_1000DPI: + case ADNS2080_RESOLUTION_1250DPI: + case ADNS2080_RESOLUTION_1500DPI: + case ADNS2080_RESOLUTION_1750DPI: + case ADNS2080_RESOLUTION_2000DPI: + // Clear resolution bits [4:2] + databyte &= ~(0x1C); // 0b00011100; + // Set resolution bits + databyte |= (uint8_t)((uint8_t)resolution << 2); + break; + + default: + status = ADNS2080_INVALID_PARAMETER; + break; + } + + if (status == ADNS2080_OK) + { + sdio_write_byte(REG_MOUSE_CTRL, databyte); + } + + return status; +} + +adns2080_status_t adns2080_motion_bits_set(adns2080_motion_bits_t motion_bits) +{ + uint8_t databyte = sdio_read_byte(REG_MOUSE_CTRL); + adns2080_status_t status = ADNS2080_OK; + + switch (motion_bits) + { + case ADNS2080_MOTION_BITS_8: + databyte &= ~(REG_MOUSE_CTRL_BIT_REPORTING); + break; + + case ADNS2080_MOTION_BITS_12: + databyte |= (REG_MOUSE_CTRL_BIT_REPORTING); + break; + + default: + status = ADNS2080_INVALID_PARAMETER; + break; + } + + if (status == ADNS2080_OK) + { + sdio_write_byte(REG_MOUSE_CTRL, databyte); + } + + return status; +} + +void adns2080_rest_periods_set(uint8_t rest1_period, uint8_t rest2_period, uint8_t rest3_period) +{ + adns2080_mode_t current_mode = adns2080_force_mode_read(); + adns2080_force_mode_set(ADNS2080_MODE_RUN1); + sdio_write_byte(REG_REST1_PERIOD, rest1_period); + sdio_write_byte(REG_REST2_PERIOD, rest2_period); + sdio_write_byte(REG_REST3_PERIOD, rest3_period); + adns2080_force_mode_set(current_mode); +} + +void adns2080_downshift_times_set(uint8_t run_to_rest1_mode_time, uint8_t rest1_to_rest2_mode_time, uint8_t rest2_to_rest3_mode_time) +{ + adns2080_mode_t current_mode = adns2080_force_mode_read(); + adns2080_force_mode_set(ADNS2080_MODE_RUN1); + sdio_write_byte(REG_RUN_DOWNSHIFT, run_to_rest1_mode_time); + sdio_write_byte(REG_REST1_DOWNSHIFT, rest1_to_rest2_mode_time); + sdio_write_byte(REG_REST2_DOWNSHIFT, rest2_to_rest3_mode_time); + adns2080_force_mode_set(current_mode); +} + +adns2080_mode_t adns2080_force_mode_read(void) +{ + return (adns2080_mode_t)((sdio_read_byte(REG_PERFORMANCE) >> 4) & 0x07); +} + +void adns2080_force_mode_set(adns2080_mode_t mode) +{ + sdio_write_byte(REG_PERFORMANCE, (uint8_t)((uint8_t)mode << 4)); +} + +/*lint --flb "Leave library region" */ diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/drivers_ext/adns2080/adns2080.h b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/drivers_ext/adns2080/adns2080.h new file mode 100644 index 0000000..1ea60b6 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/drivers_ext/adns2080/adns2080.h @@ -0,0 +1,317 @@ +/** + * Copyright (c) 2009 - 2018, Nordic Semiconductor ASA + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 3. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 4. This software, with or without modification, must only be used with a + * Nordic Semiconductor ASA integrated circuit. + * + * 5. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +#ifndef ADNS2080_H +#define ADNS2080_H + +/*lint ++flb "Enter library region" */ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** @file +* @brief ADNS2080 mouse sensor driver +* +* @defgroup nrf_drivers_adns2080 ADNS2080 driver +* @{ +* @ingroup ext_drivers +* @brief ADNS2080 mouse sensor driver. +*/ + +/** + * Describes return values for @ref adns2080_init. + */ +typedef enum +{ + ADNS2080_OK, /*!< Operation was succesful */ + ADNS2080_SERIAL_COMM_FAILURE, /*!< Serial communication failed */ + ADNS2080_CHIP_NOT_DETECTED, /*!< Product/Revision ID was not what was expected */ + ADNS2080_INVALID_PARAMETER /*!< Given parameters were not valid */ +} adns2080_status_t; + +/** + * ADNS2080 motion output pin polarity values. + */ +typedef enum +{ + ADNS2080_MOTION_OUTPUT_POLARITY_LOW = 0, /*!< Motion output polarity active low */ + ADNS2080_MOTION_OUTPUT_POLARITY_HIGH = 1 /*!< Motion output polarity active high */ +} motion_output_polarity_t; + +/** + * Motion output pin configuration. + */ +typedef enum +{ + ADNS2080_MOTION_OUTPUT_SENSITIVITY_LEVEL = 0, /*!< Motion output pin will be driven low/high (depending on the polarity setting) as long as there is motion data in DELTA registers */ + ADNS2080_MOTION_OUTPUT_SENSITIVITY_EDGE = 1 /*!< Motion output pin will be driven low/high (depending on the polarity setting) for 380 ns when motion is detected during rest modes */ +} motion_output_sensitivity_t; + +/** + * Mouse sensor resolution values. + */ +typedef enum +{ + ADNS2080_RESOLUTION_250DPI = 1, /*!< 250 dpi resolution */ + ADNS2080_RESOLUTION_500DPI = 2, /*!< 500 dpi resolution */ + ADNS2080_RESOLUTION_1000DPI = 0, /*!< 1000 dpi resolution */ + ADNS2080_RESOLUTION_1250DPI = 3, /*!< 1250 dpi resolution */ + ADNS2080_RESOLUTION_1500DPI = 4, /*!< 1500 dpi resolution */ + ADNS2080_RESOLUTION_1750DPI = 5, /*!< 1750 dpi resolution */ + ADNS2080_RESOLUTION_2000DPI = 6 /*!< 2000 dpi resolution */ +} adns2080_resolution_t; + +/** + * Mouse sensor forced mode options. + */ +typedef enum +{ + ADNS2080_MODE_NORMAL = 0, /*!< Normal operation mode */ + ADNS2080_MODE_REST1 = 1, /*!< Rest1 operation mode */ + ADNS2080_MODE_REST2 = 2, /*!< Rest2 operation mode */ + ADNS2080_MODE_REST3 = 3, /*!< Rest3 operation mode */ + ADNS2080_MODE_RUN1 = 4, /*!< Run1 operation mode */ + ADNS2080_MODE_RUN2 = 5, /*!< Run2 operation mode */ + ADNS2080_MODE_IDLE = 6 /*!< Idle operation mode */ +} adns2080_mode_t; + +/** + * Mouse sensor motion reporting bits. + */ +typedef enum +{ + ADNS2080_MOTION_BITS_8 = 0, /*!< Motion reporting uses 8 bits */ + ADNS2080_MOTION_BITS_12 = 1 /*!< Motion reporting uses 12 bits */ +} adns2080_motion_bits_t; + +/** + * @brief Function for initializing the mouse sensor chip. + * + * Valid mouse sensor information will be available 50 milliseconds after this + * function finishes. + * + * @return + * @retval ADNS2080_OK Mouse sensor was initialized succesfully. + * @retval ADNS2080_SERIAL_COMM_FAILURE Serial communications failure. + * @retval ADNS2080_CHIP_NOT_DETECTED Could not find revision 0 ADNS2080 chip. + */ +adns2080_status_t adns2080_init(void); + +/** + * @brief Function for resetting the mouse sensor chip. + * + * Valid mouse sensor information will be available 50 milliseconds after this + * function finishes. + * All register settings will be lost and need to be reloaded. + * + */ +void adns2080_reset(void); + +/** + * @brief Function for reading mouse sensor product ID. + * + * Chip is expected to be initialized before calling this function. + * Returned product ID should always be 0x2A. + * + * @return Product ID. + */ +uint8_t adns2080_product_id_read(void); + +/** + * @brief Function for reading mouse sensor revision ID. + * + * Chip is expected to be initialized before calling this function. + * + * @return Product ID. + */ +uint8_t adns2080_revision_id_read(void); // also note there is "not rev id" register + +/** + * @brief Function for powering down the mouse sensor. + * + * Chip is expected to be initialized before calling this function. + * Serial port should not be accessed during the power down. To exit the power + * down mode, @ref adns2080_wakeup must be called. + * + */ +void adns2080_powerdown(void); + +/** + * @brief Function for waking up the mouse sensor. + * + * After wakeup, all mouse sensor settings must be reloaded. Valid mouse sensor + * information will be available 55 milliseconds after this function finishes. + */ +void adns2080_wakeup(void); + +/** + * @brief Function for configuring the MOTION interrupt output pin. + * + * When motion is detected by the mouse sensor, the chip has a MOTION pin + * indicating there is motion data in DELTA_X and DELTA_Y registers. This + * function configures the polarity and sensitivity of that pin. + * + * Chip is expected to be initialized before calling this function. + * + * @param polarity MOTION output pin is either active LOW (default) or active HIGH + * @param sensitivity Level or Edge (default) sensitive + * @return + * @retval ADNS2080_OK Operation succeeded. + * @retval ADNS2080_INVALID_PARAMETER One of the parameters was not within valid range. + */ +adns2080_status_t adns2080_motion_interrupt_set(motion_output_polarity_t polarity, motion_output_sensitivity_t sensitivity); + +/** + * @brief Function for setting mouse sensor resolution. + * + * Chip is expected to be initialized before calling this function. + * + * @param resolution Desired resolution. + * @return + * @retval ADNS2080_OK Operation succeeded. + * @retval ADNS2080_INVALID_PARAMETER One of the parameters was not within valid range. + */ +adns2080_status_t adns2080_resolution_set(adns2080_resolution_t resolution); + +/** + * @brief Function for setting number of bits used for mouse sensor motion reporting. + * + * Chip is expected to be initialized before calling this function. + * + * @param motion_bits Desired number of bits. + * @return + * @retval ADNS2080_OK Operation succeeded. + * @retval ADNS2080_INVALID_PARAMETER One of the parameters was not within valid range. + */ +adns2080_status_t adns2080_motion_bits_set(adns2080_motion_bits_t motion_bits); + +/** + * @brief Function for reading number of bits used for mouse sensor motion reporting. + * + * Chip is expected to be initialized before calling this function. + * + * @return motion_bits Number of bits. + */ +adns2080_motion_bits_t adns2080_motion_bits_read(void); + +/** + * @brief Function for reading X- and Y-axis movement (in counts) since last report. + * + * Absolute value is determined by resolution. + * Chip is expected to be initialized before calling this function. + * + * @param p_delta_x Location to store X-axis movement + * @param p_delta_y Location to store Y-axis movement + */ +void adns2080_movement_read(int16_t *p_delta_x, int16_t *p_delta_y); + +/** + * @brief Function for checking if motion has been detected since last call. + * + * Chip is expected to be initialized before calling this function. + * + * @return + * @retval true, if movement has been detected + * @retval false, if no movement has been detected + */ +bool adns2080_is_motion_detected(void); + +/** + * @brief Function for setting mouse sensor Rest1, Rest2 and Rest3 mode motion detection time period. + * + * Allowed range for the periods is 0x01 to 0xFD. + * Resulting period is derived from the following equation : + * Period = (Rest period + 1) * 10 milliseconds + * Chip is expected to be initialized before calling this function. + * + * @param rest1_period Rest1 period + * @param rest2_period Rest2 period + * @param rest3_period Rest3 period + */ +void adns2080_rest_periods_set(uint8_t rest1_period, uint8_t rest2_period, uint8_t rest3_period); + +/** + * @brief Function for setting mouse sensor mode downshift time periods. + * + * Allowed range for run_to_rest1_mode_time period is 0x00 to 0xFF. + * Allowed range for rest1_to_rest2_mode_time period is 0x01 to 0xFF. + * Allowed range for rest2_to_rest3_mode_time period is 0x01 to 0xFF. + * + * Chip is expected to be initialized before calling this function. + * + * @param run_to_rest1_mode_time Run mode to Rest1 mode downshift time period (Time = run_to_rest1_mode_time * 8 * 4) + * @param rest1_to_rest2_mode_time Rest1 mode to Rest2 mode downshift time period (Time = rest1_to_rest2_mode_time * rest1_period * 16) + * @param rest2_to_rest3_mode_time Rest2 mode to Rest3 mode downshift time period (Time = rest2_to_rest3_mode_time * rest2_period * 128) + */ +void adns2080_downshift_times_set(uint8_t run_to_rest1_mode_time, uint8_t rest1_to_rest2_mode_time, uint8_t rest2_to_rest3_mode_time); + +/** + * @brief Function for forcing mouse sensor to a certain operating mode. + * + * Chip is expected to be initialized before calling this function. + * Normal operation will not continue until this function is called with ADNS2080_MODE_NORMAL parameter. + * + * @param mode Mode to force the sensor to. + */ +void adns2080_force_mode_set(adns2080_mode_t mode); + +/** + * @brief Function for reading the current forced operating mode. + * + * Chip is expected to be initialized before calling this function. + * + * @return Mode the sensor is forced to. + */ +adns2080_mode_t adns2080_force_mode_read(void); + +/** + *@} + **/ + +/*lint --flb "Leave library region" */ + +#ifdef __cplusplus +} +#endif + +#endif -- cgit v1.2.3