Mouse code for the MacroRat

Dependencies:   ITG3200 QEI

Committer:
sahilmgandhi
Date:
Sat Jun 03 00:22:44 2017 +0000
Revision:
46:b156ef445742
Parent:
18:6a4db94011d3
Final code for internal battlebot competition.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
sahilmgandhi 18:6a4db94011d3 1 /*
sahilmgandhi 18:6a4db94011d3 2 * Copyright (c) 2000 Nordic Semiconductor ASA
sahilmgandhi 18:6a4db94011d3 3 * All rights reserved.
sahilmgandhi 18:6a4db94011d3 4 *
sahilmgandhi 18:6a4db94011d3 5 * Redistribution and use in source and binary forms, with or without modification,
sahilmgandhi 18:6a4db94011d3 6 * are permitted provided that the following conditions are met:
sahilmgandhi 18:6a4db94011d3 7 *
sahilmgandhi 18:6a4db94011d3 8 * 1. Redistributions of source code must retain the above copyright notice, this list
sahilmgandhi 18:6a4db94011d3 9 * of conditions and the following disclaimer.
sahilmgandhi 18:6a4db94011d3 10 *
sahilmgandhi 18:6a4db94011d3 11 * 2. Redistributions in binary form, except as embedded into a Nordic Semiconductor ASA
sahilmgandhi 18:6a4db94011d3 12 * integrated circuit in a product or a software update for such product, must reproduce
sahilmgandhi 18:6a4db94011d3 13 * the above copyright notice, this list of conditions and the following disclaimer in
sahilmgandhi 18:6a4db94011d3 14 * the documentation and/or other materials provided with the distribution.
sahilmgandhi 18:6a4db94011d3 15 *
sahilmgandhi 18:6a4db94011d3 16 * 3. Neither the name of Nordic Semiconductor ASA nor the names of its contributors may be
sahilmgandhi 18:6a4db94011d3 17 * used to endorse or promote products derived from this software without specific prior
sahilmgandhi 18:6a4db94011d3 18 * written permission.
sahilmgandhi 18:6a4db94011d3 19 *
sahilmgandhi 18:6a4db94011d3 20 * 4. This software, with or without modification, must only be used with a
sahilmgandhi 18:6a4db94011d3 21 * Nordic Semiconductor ASA integrated circuit.
sahilmgandhi 18:6a4db94011d3 22 *
sahilmgandhi 18:6a4db94011d3 23 * 5. Any software provided in binary or object form under this license must not be reverse
sahilmgandhi 18:6a4db94011d3 24 * engineered, decompiled, modified and/or disassembled.
sahilmgandhi 18:6a4db94011d3 25 *
sahilmgandhi 18:6a4db94011d3 26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
sahilmgandhi 18:6a4db94011d3 27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
sahilmgandhi 18:6a4db94011d3 28 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
sahilmgandhi 18:6a4db94011d3 29 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
sahilmgandhi 18:6a4db94011d3 30 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
sahilmgandhi 18:6a4db94011d3 31 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
sahilmgandhi 18:6a4db94011d3 32 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
sahilmgandhi 18:6a4db94011d3 33 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
sahilmgandhi 18:6a4db94011d3 34 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
sahilmgandhi 18:6a4db94011d3 35 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
sahilmgandhi 18:6a4db94011d3 36 *
sahilmgandhi 18:6a4db94011d3 37 */
sahilmgandhi 18:6a4db94011d3 38
sahilmgandhi 18:6a4db94011d3 39
sahilmgandhi 18:6a4db94011d3 40 /**
sahilmgandhi 18:6a4db94011d3 41 @addtogroup BLE_L2CAP Logical Link Control and Adaptation Protocol (L2CAP)
sahilmgandhi 18:6a4db94011d3 42 @{
sahilmgandhi 18:6a4db94011d3 43 @brief Definitions and prototypes for the L2CAP interface.
sahilmgandhi 18:6a4db94011d3 44 */
sahilmgandhi 18:6a4db94011d3 45
sahilmgandhi 18:6a4db94011d3 46 #ifndef NRF_BLE_L2CAP_H__
sahilmgandhi 18:6a4db94011d3 47 #define NRF_BLE_L2CAP_H__
sahilmgandhi 18:6a4db94011d3 48
sahilmgandhi 18:6a4db94011d3 49 #include "nrf_ble_types.h"
sahilmgandhi 18:6a4db94011d3 50 #include "nrf_ble_ranges.h"
sahilmgandhi 18:6a4db94011d3 51 #include "nrf_ble_err.h"
sahilmgandhi 18:6a4db94011d3 52 #include "nrf_svc.h"
sahilmgandhi 18:6a4db94011d3 53
sahilmgandhi 18:6a4db94011d3 54 #ifdef __cplusplus
sahilmgandhi 18:6a4db94011d3 55 extern "C" {
sahilmgandhi 18:6a4db94011d3 56 #endif
sahilmgandhi 18:6a4db94011d3 57
sahilmgandhi 18:6a4db94011d3 58 /**@addtogroup BLE_L2CAP_ENUMERATIONS Enumerations
sahilmgandhi 18:6a4db94011d3 59 * @{ */
sahilmgandhi 18:6a4db94011d3 60
sahilmgandhi 18:6a4db94011d3 61 /**@brief L2CAP API SVC numbers. */
sahilmgandhi 18:6a4db94011d3 62 enum BLE_L2CAP_SVCS
sahilmgandhi 18:6a4db94011d3 63 {
sahilmgandhi 18:6a4db94011d3 64 SD_BLE_L2CAP_CID_REGISTER = BLE_L2CAP_SVC_BASE, /**< Register a CID. */
sahilmgandhi 18:6a4db94011d3 65 SD_BLE_L2CAP_CID_UNREGISTER, /**< Unregister a CID. */
sahilmgandhi 18:6a4db94011d3 66 SD_BLE_L2CAP_TX /**< Transmit a packet. */
sahilmgandhi 18:6a4db94011d3 67 };
sahilmgandhi 18:6a4db94011d3 68
sahilmgandhi 18:6a4db94011d3 69 /**@brief L2CAP Event IDs. */
sahilmgandhi 18:6a4db94011d3 70 enum BLE_L2CAP_EVTS
sahilmgandhi 18:6a4db94011d3 71 {
sahilmgandhi 18:6a4db94011d3 72 BLE_L2CAP_EVT_RX = BLE_L2CAP_EVT_BASE /**< L2CAP packet received. */
sahilmgandhi 18:6a4db94011d3 73 };
sahilmgandhi 18:6a4db94011d3 74
sahilmgandhi 18:6a4db94011d3 75 /** @} */
sahilmgandhi 18:6a4db94011d3 76
sahilmgandhi 18:6a4db94011d3 77 /**@addtogroup BLE_L2CAP_DEFINES Defines
sahilmgandhi 18:6a4db94011d3 78 * @{ */
sahilmgandhi 18:6a4db94011d3 79
sahilmgandhi 18:6a4db94011d3 80 /**@defgroup BLE_ERRORS_L2CAP SVC return values specific to L2CAP
sahilmgandhi 18:6a4db94011d3 81 * @{ */
sahilmgandhi 18:6a4db94011d3 82 #define BLE_ERROR_L2CAP_CID_IN_USE (NRF_L2CAP_ERR_BASE + 0x000) /**< CID already in use. */
sahilmgandhi 18:6a4db94011d3 83 /** @} */
sahilmgandhi 18:6a4db94011d3 84
sahilmgandhi 18:6a4db94011d3 85 /**@brief Default L2CAP MTU. */
sahilmgandhi 18:6a4db94011d3 86 #define BLE_L2CAP_MTU_DEF (23)
sahilmgandhi 18:6a4db94011d3 87
sahilmgandhi 18:6a4db94011d3 88 /**@brief Invalid Channel Identifier. */
sahilmgandhi 18:6a4db94011d3 89 #define BLE_L2CAP_CID_INVALID (0x0000)
sahilmgandhi 18:6a4db94011d3 90
sahilmgandhi 18:6a4db94011d3 91 /**@brief Dynamic Channel Identifier base. */
sahilmgandhi 18:6a4db94011d3 92 #define BLE_L2CAP_CID_DYN_BASE (0x0040)
sahilmgandhi 18:6a4db94011d3 93
sahilmgandhi 18:6a4db94011d3 94 /**@brief Maximum amount of dynamic CIDs. */
sahilmgandhi 18:6a4db94011d3 95 #define BLE_L2CAP_CID_DYN_MAX (8)
sahilmgandhi 18:6a4db94011d3 96
sahilmgandhi 18:6a4db94011d3 97 /** @} */
sahilmgandhi 18:6a4db94011d3 98
sahilmgandhi 18:6a4db94011d3 99 /**@addtogroup BLE_L2CAP_STRUCTURES Structures
sahilmgandhi 18:6a4db94011d3 100 * @{ */
sahilmgandhi 18:6a4db94011d3 101
sahilmgandhi 18:6a4db94011d3 102 /**@brief Packet header format for L2CAP transmission. */
sahilmgandhi 18:6a4db94011d3 103 typedef struct
sahilmgandhi 18:6a4db94011d3 104 {
sahilmgandhi 18:6a4db94011d3 105 uint16_t len; /**< Length of valid info in data member. */
sahilmgandhi 18:6a4db94011d3 106 uint16_t cid; /**< Channel ID on which packet is transmitted. */
sahilmgandhi 18:6a4db94011d3 107 } ble_l2cap_header_t;
sahilmgandhi 18:6a4db94011d3 108
sahilmgandhi 18:6a4db94011d3 109
sahilmgandhi 18:6a4db94011d3 110 /**@brief L2CAP Received packet event report. */
sahilmgandhi 18:6a4db94011d3 111 typedef struct
sahilmgandhi 18:6a4db94011d3 112 {
sahilmgandhi 18:6a4db94011d3 113 ble_l2cap_header_t header; /**< L2CAP packet header. */
sahilmgandhi 18:6a4db94011d3 114 uint8_t data[1]; /**< Packet data. @note This is a variable length array. The size of 1 indicated is only a placeholder for compilation.
sahilmgandhi 18:6a4db94011d3 115 See @ref sd_ble_evt_get for more information on how to use event structures with variable length array members. */
sahilmgandhi 18:6a4db94011d3 116 } ble_l2cap_evt_rx_t;
sahilmgandhi 18:6a4db94011d3 117
sahilmgandhi 18:6a4db94011d3 118
sahilmgandhi 18:6a4db94011d3 119 /**@brief L2CAP event callback event structure. */
sahilmgandhi 18:6a4db94011d3 120 typedef struct
sahilmgandhi 18:6a4db94011d3 121 {
sahilmgandhi 18:6a4db94011d3 122 uint16_t conn_handle; /**< Connection Handle on which event occured. */
sahilmgandhi 18:6a4db94011d3 123 union
sahilmgandhi 18:6a4db94011d3 124 {
sahilmgandhi 18:6a4db94011d3 125 ble_l2cap_evt_rx_t rx; /**< RX Event parameters. */
sahilmgandhi 18:6a4db94011d3 126 } params; /**< Event Parameters. */
sahilmgandhi 18:6a4db94011d3 127 } ble_l2cap_evt_t;
sahilmgandhi 18:6a4db94011d3 128
sahilmgandhi 18:6a4db94011d3 129 /** @} */
sahilmgandhi 18:6a4db94011d3 130
sahilmgandhi 18:6a4db94011d3 131 /**@addtogroup BLE_L2CAP_FUNCTIONS Functions
sahilmgandhi 18:6a4db94011d3 132 * @{ */
sahilmgandhi 18:6a4db94011d3 133
sahilmgandhi 18:6a4db94011d3 134 /**@brief Register a CID with L2CAP.
sahilmgandhi 18:6a4db94011d3 135 *
sahilmgandhi 18:6a4db94011d3 136 * @details This registers a higher protocol layer with the L2CAP multiplexer, and is requried prior to all operations on the CID.
sahilmgandhi 18:6a4db94011d3 137 *
sahilmgandhi 18:6a4db94011d3 138 * @mscs
sahilmgandhi 18:6a4db94011d3 139 * @mmsc{@ref BLE_L2CAP_API_MSC}
sahilmgandhi 18:6a4db94011d3 140 * @endmscs
sahilmgandhi 18:6a4db94011d3 141 *
sahilmgandhi 18:6a4db94011d3 142 * @param[in] cid L2CAP CID.
sahilmgandhi 18:6a4db94011d3 143 *
sahilmgandhi 18:6a4db94011d3 144 * @retval ::NRF_SUCCESS Successfully registered a CID with the L2CAP layer.
sahilmgandhi 18:6a4db94011d3 145 * @retval ::NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied, CID must be above @ref BLE_L2CAP_CID_DYN_BASE.
sahilmgandhi 18:6a4db94011d3 146 * @retval ::BLE_ERROR_L2CAP_CID_IN_USE L2CAP CID already in use.
sahilmgandhi 18:6a4db94011d3 147 * @retval ::NRF_ERROR_NO_MEM Not enough memory to complete operation.
sahilmgandhi 18:6a4db94011d3 148 */
sahilmgandhi 18:6a4db94011d3 149 SVCALL(SD_BLE_L2CAP_CID_REGISTER, uint32_t, sd_ble_l2cap_cid_register(uint16_t cid));
sahilmgandhi 18:6a4db94011d3 150
sahilmgandhi 18:6a4db94011d3 151 /**@brief Unregister a CID with L2CAP.
sahilmgandhi 18:6a4db94011d3 152 *
sahilmgandhi 18:6a4db94011d3 153 * @details This unregisters a previously registerd higher protocol layer with the L2CAP multiplexer.
sahilmgandhi 18:6a4db94011d3 154 *
sahilmgandhi 18:6a4db94011d3 155 * @mscs
sahilmgandhi 18:6a4db94011d3 156 * @mmsc{@ref BLE_L2CAP_API_MSC}
sahilmgandhi 18:6a4db94011d3 157 * @endmscs
sahilmgandhi 18:6a4db94011d3 158 *
sahilmgandhi 18:6a4db94011d3 159 * @param[in] cid L2CAP CID.
sahilmgandhi 18:6a4db94011d3 160 *
sahilmgandhi 18:6a4db94011d3 161 * @retval ::NRF_SUCCESS Successfully unregistered the CID.
sahilmgandhi 18:6a4db94011d3 162 * @retval ::NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied.
sahilmgandhi 18:6a4db94011d3 163 * @retval ::NRF_ERROR_NOT_FOUND CID not previously registered.
sahilmgandhi 18:6a4db94011d3 164 */
sahilmgandhi 18:6a4db94011d3 165 SVCALL(SD_BLE_L2CAP_CID_UNREGISTER, uint32_t, sd_ble_l2cap_cid_unregister(uint16_t cid));
sahilmgandhi 18:6a4db94011d3 166
sahilmgandhi 18:6a4db94011d3 167 /**@brief Transmit an L2CAP packet.
sahilmgandhi 18:6a4db94011d3 168 *
sahilmgandhi 18:6a4db94011d3 169 * @note It is important to note that a call to this function will <b>consume an application packet</b>, and will therefore
sahilmgandhi 18:6a4db94011d3 170 * generate a @ref BLE_EVT_TX_COMPLETE event when the packet has been transmitted.
sahilmgandhi 18:6a4db94011d3 171 * Please see the documentation of @ref sd_ble_tx_packet_count_get for more details.
sahilmgandhi 18:6a4db94011d3 172 *
sahilmgandhi 18:6a4db94011d3 173 * @events
sahilmgandhi 18:6a4db94011d3 174 * @event{@ref BLE_EVT_TX_COMPLETE}
sahilmgandhi 18:6a4db94011d3 175 * @event{@ref BLE_L2CAP_EVT_RX}
sahilmgandhi 18:6a4db94011d3 176 * @endevents
sahilmgandhi 18:6a4db94011d3 177 *
sahilmgandhi 18:6a4db94011d3 178 * @mscs
sahilmgandhi 18:6a4db94011d3 179 * @mmsc{@ref BLE_L2CAP_API_MSC}
sahilmgandhi 18:6a4db94011d3 180 * @endmscs
sahilmgandhi 18:6a4db94011d3 181 *
sahilmgandhi 18:6a4db94011d3 182 * @param[in] conn_handle Connection Handle.
sahilmgandhi 18:6a4db94011d3 183 * @param[in] p_header Pointer to a packet header containing length and CID.
sahilmgandhi 18:6a4db94011d3 184 * @param[in] p_data Pointer to the data to be transmitted.
sahilmgandhi 18:6a4db94011d3 185 *
sahilmgandhi 18:6a4db94011d3 186 * @retval ::NRF_SUCCESS Successfully queued an L2CAP packet for transmission.
sahilmgandhi 18:6a4db94011d3 187 * @retval ::NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
sahilmgandhi 18:6a4db94011d3 188 * @retval ::NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied, CIDs must be registered beforehand with @ref sd_ble_l2cap_cid_register.
sahilmgandhi 18:6a4db94011d3 189 * @retval ::NRF_ERROR_NOT_FOUND CID not found.
sahilmgandhi 18:6a4db94011d3 190 * @retval ::NRF_ERROR_NO_MEM Not enough memory to complete operation.
sahilmgandhi 18:6a4db94011d3 191 * @retval ::BLE_ERROR_NO_TX_PACKETS Not enough application packets available.
sahilmgandhi 18:6a4db94011d3 192 * @retval ::NRF_ERROR_DATA_SIZE Invalid data size(s) supplied, see @ref BLE_L2CAP_MTU_DEF.
sahilmgandhi 18:6a4db94011d3 193 */
sahilmgandhi 18:6a4db94011d3 194 SVCALL(SD_BLE_L2CAP_TX, uint32_t, sd_ble_l2cap_tx(uint16_t conn_handle, ble_l2cap_header_t const *p_header, uint8_t const *p_data));
sahilmgandhi 18:6a4db94011d3 195
sahilmgandhi 18:6a4db94011d3 196 /** @} */
sahilmgandhi 18:6a4db94011d3 197
sahilmgandhi 18:6a4db94011d3 198 #ifdef __cplusplus
sahilmgandhi 18:6a4db94011d3 199 }
sahilmgandhi 18:6a4db94011d3 200 #endif
sahilmgandhi 18:6a4db94011d3 201 #endif // NRF_BLE_L2CAP_H__
sahilmgandhi 18:6a4db94011d3 202
sahilmgandhi 18:6a4db94011d3 203 /**
sahilmgandhi 18:6a4db94011d3 204 @}
sahilmgandhi 18:6a4db94011d3 205 */