Mouse code for the MacroRat

Dependencies:   ITG3200 QEI

Committer:
sahilmgandhi
Date:
Sun May 14 23:18:57 2017 +0000
Revision:
18:6a4db94011d3
Publishing again

Who changed what in which revision?

UserRevisionLine numberNew contents of line
sahilmgandhi 18:6a4db94011d3 1 /* mbed Microcontroller Library
sahilmgandhi 18:6a4db94011d3 2 * Copyright (c) 2006-2016 ARM Limited
sahilmgandhi 18:6a4db94011d3 3 *
sahilmgandhi 18:6a4db94011d3 4 * Licensed under the Apache License, Version 2.0 (the "License");
sahilmgandhi 18:6a4db94011d3 5 * you may not use this file except in compliance with the License.
sahilmgandhi 18:6a4db94011d3 6 * You may obtain a copy of the License at
sahilmgandhi 18:6a4db94011d3 7 *
sahilmgandhi 18:6a4db94011d3 8 * http://www.apache.org/licenses/LICENSE-2.0
sahilmgandhi 18:6a4db94011d3 9 *
sahilmgandhi 18:6a4db94011d3 10 * Unless required by applicable law or agreed to in writing, software
sahilmgandhi 18:6a4db94011d3 11 * distributed under the License is distributed on an "AS IS" BASIS,
sahilmgandhi 18:6a4db94011d3 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
sahilmgandhi 18:6a4db94011d3 13 * See the License for the specific language governing permissions and
sahilmgandhi 18:6a4db94011d3 14 * limitations under the License.
sahilmgandhi 18:6a4db94011d3 15 */
sahilmgandhi 18:6a4db94011d3 16 #include <stddef.h>
sahilmgandhi 18:6a4db94011d3 17 #include "us_ticker_api.h"
sahilmgandhi 18:6a4db94011d3 18 #include "PeripheralNames.h"
sahilmgandhi 18:6a4db94011d3 19 #include "hal_tick.h"
sahilmgandhi 18:6a4db94011d3 20
sahilmgandhi 18:6a4db94011d3 21 // A 32-bit timer is used
sahilmgandhi 18:6a4db94011d3 22 #if !TIM_MST_16BIT
sahilmgandhi 18:6a4db94011d3 23
sahilmgandhi 18:6a4db94011d3 24 TIM_HandleTypeDef TimMasterHandle;
sahilmgandhi 18:6a4db94011d3 25
sahilmgandhi 18:6a4db94011d3 26 static int us_ticker_inited = 0;
sahilmgandhi 18:6a4db94011d3 27
sahilmgandhi 18:6a4db94011d3 28 void us_ticker_init(void)
sahilmgandhi 18:6a4db94011d3 29 {
sahilmgandhi 18:6a4db94011d3 30 if (us_ticker_inited) return;
sahilmgandhi 18:6a4db94011d3 31 us_ticker_inited = 1;
sahilmgandhi 18:6a4db94011d3 32
sahilmgandhi 18:6a4db94011d3 33 TimMasterHandle.Instance = TIM_MST;
sahilmgandhi 18:6a4db94011d3 34
sahilmgandhi 18:6a4db94011d3 35 HAL_InitTick(0); // The passed value is not used
sahilmgandhi 18:6a4db94011d3 36 }
sahilmgandhi 18:6a4db94011d3 37
sahilmgandhi 18:6a4db94011d3 38 uint32_t us_ticker_read()
sahilmgandhi 18:6a4db94011d3 39 {
sahilmgandhi 18:6a4db94011d3 40 if (!us_ticker_inited) us_ticker_init();
sahilmgandhi 18:6a4db94011d3 41 return TIM_MST->CNT;
sahilmgandhi 18:6a4db94011d3 42 }
sahilmgandhi 18:6a4db94011d3 43
sahilmgandhi 18:6a4db94011d3 44 void us_ticker_set_interrupt(timestamp_t timestamp)
sahilmgandhi 18:6a4db94011d3 45 {
sahilmgandhi 18:6a4db94011d3 46 TimMasterHandle.Instance = TIM_MST;
sahilmgandhi 18:6a4db94011d3 47 // Set new output compare value
sahilmgandhi 18:6a4db94011d3 48 __HAL_TIM_SET_COMPARE(&TimMasterHandle, TIM_CHANNEL_1, (uint32_t)timestamp);
sahilmgandhi 18:6a4db94011d3 49 // Enable IT
sahilmgandhi 18:6a4db94011d3 50 __HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC1);
sahilmgandhi 18:6a4db94011d3 51 }
sahilmgandhi 18:6a4db94011d3 52
sahilmgandhi 18:6a4db94011d3 53 void us_ticker_disable_interrupt(void)
sahilmgandhi 18:6a4db94011d3 54 {
sahilmgandhi 18:6a4db94011d3 55 TimMasterHandle.Instance = TIM_MST;
sahilmgandhi 18:6a4db94011d3 56 __HAL_TIM_DISABLE_IT(&TimMasterHandle, TIM_IT_CC1);
sahilmgandhi 18:6a4db94011d3 57 }
sahilmgandhi 18:6a4db94011d3 58
sahilmgandhi 18:6a4db94011d3 59 void us_ticker_clear_interrupt(void)
sahilmgandhi 18:6a4db94011d3 60 {
sahilmgandhi 18:6a4db94011d3 61 TimMasterHandle.Instance = TIM_MST;
sahilmgandhi 18:6a4db94011d3 62 __HAL_TIM_CLEAR_IT(&TimMasterHandle, TIM_IT_CC1);
sahilmgandhi 18:6a4db94011d3 63 }
sahilmgandhi 18:6a4db94011d3 64
sahilmgandhi 18:6a4db94011d3 65 #endif // !TIM_MST_16BIT