Mouse code for the MacroRat
mbed-dev/targets/TARGET_ARM_SSG/TARGET_MPS2/analogin_api.c@18:6a4db94011d3, 2017-05-14 (annotated)
- Committer:
- sahilmgandhi
- Date:
- Sun May 14 23:18:57 2017 +0000
- Revision:
- 18:6a4db94011d3
Publishing again
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sahilmgandhi | 18:6a4db94011d3 | 1 | /* mbed Microcontroller Library |
sahilmgandhi | 18:6a4db94011d3 | 2 | * Copyright (c) 2006-2015 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 "mbed_assert.h" |
sahilmgandhi | 18:6a4db94011d3 | 17 | #include "analogin_api.h" |
sahilmgandhi | 18:6a4db94011d3 | 18 | |
sahilmgandhi | 18:6a4db94011d3 | 19 | #include "cmsis.h" |
sahilmgandhi | 18:6a4db94011d3 | 20 | #include "pinmap.h" |
sahilmgandhi | 18:6a4db94011d3 | 21 | |
sahilmgandhi | 18:6a4db94011d3 | 22 | #define ADC_12BIT_RANGE 0xFFF |
sahilmgandhi | 18:6a4db94011d3 | 23 | |
sahilmgandhi | 18:6a4db94011d3 | 24 | static const PinMap PinMap_ADC[] = { |
sahilmgandhi | 18:6a4db94011d3 | 25 | {A0_0, ADC0_0, 0}, |
sahilmgandhi | 18:6a4db94011d3 | 26 | {A0_1, ADC0_1, 0}, |
sahilmgandhi | 18:6a4db94011d3 | 27 | {A0_2, ADC0_2, 0}, |
sahilmgandhi | 18:6a4db94011d3 | 28 | {A0_3, ADC0_3, 0}, |
sahilmgandhi | 18:6a4db94011d3 | 29 | {A0_4, ADC0_4, 0}, |
sahilmgandhi | 18:6a4db94011d3 | 30 | {A0_5, ADC0_5, 0}, |
sahilmgandhi | 18:6a4db94011d3 | 31 | {A1_0, ADC0_6, 0}, |
sahilmgandhi | 18:6a4db94011d3 | 32 | {A1_1, ADC0_7, 0}, |
sahilmgandhi | 18:6a4db94011d3 | 33 | {A1_2, ADC0_8, 0}, |
sahilmgandhi | 18:6a4db94011d3 | 34 | {A1_3, ADC0_9, 0}, |
sahilmgandhi | 18:6a4db94011d3 | 35 | {A1_4, ADC0_10, 0}, |
sahilmgandhi | 18:6a4db94011d3 | 36 | {A1_5, ADC0_11, 0}, |
sahilmgandhi | 18:6a4db94011d3 | 37 | {NC, NC, 0} |
sahilmgandhi | 18:6a4db94011d3 | 38 | }; |
sahilmgandhi | 18:6a4db94011d3 | 39 | |
sahilmgandhi | 18:6a4db94011d3 | 40 | static const PinMap PinMap_SPI_SCLK[] = { |
sahilmgandhi | 18:6a4db94011d3 | 41 | {ADC_SCLK , SPI_3, 0}, |
sahilmgandhi | 18:6a4db94011d3 | 42 | {NC , NC , 0} |
sahilmgandhi | 18:6a4db94011d3 | 43 | }; |
sahilmgandhi | 18:6a4db94011d3 | 44 | |
sahilmgandhi | 18:6a4db94011d3 | 45 | static const PinMap PinMap_SPI_MOSI[] = { |
sahilmgandhi | 18:6a4db94011d3 | 46 | {ADC_MOSI, SPI_3, 0}, |
sahilmgandhi | 18:6a4db94011d3 | 47 | {NC , NC , 0} |
sahilmgandhi | 18:6a4db94011d3 | 48 | }; |
sahilmgandhi | 18:6a4db94011d3 | 49 | |
sahilmgandhi | 18:6a4db94011d3 | 50 | static const PinMap PinMap_SPI_MISO[] = { |
sahilmgandhi | 18:6a4db94011d3 | 51 | {ADC_MISO, SPI_3, 0}, |
sahilmgandhi | 18:6a4db94011d3 | 52 | {NC , NC , 0} |
sahilmgandhi | 18:6a4db94011d3 | 53 | }; |
sahilmgandhi | 18:6a4db94011d3 | 54 | |
sahilmgandhi | 18:6a4db94011d3 | 55 | static const PinMap PinMap_SPI_SSEL[] = { |
sahilmgandhi | 18:6a4db94011d3 | 56 | {ADC_SSEL, SPI_3, 0}, |
sahilmgandhi | 18:6a4db94011d3 | 57 | {NC , NC , 0} |
sahilmgandhi | 18:6a4db94011d3 | 58 | }; |
sahilmgandhi | 18:6a4db94011d3 | 59 | |
sahilmgandhi | 18:6a4db94011d3 | 60 | #define ADC_RANGE ADC_12BIT_RANGE |
sahilmgandhi | 18:6a4db94011d3 | 61 | int analog_spi_inited = 0; |
sahilmgandhi | 18:6a4db94011d3 | 62 | |
sahilmgandhi | 18:6a4db94011d3 | 63 | void analogin_init(analogin_t *obj, PinName pin) { |
sahilmgandhi | 18:6a4db94011d3 | 64 | |
sahilmgandhi | 18:6a4db94011d3 | 65 | obj->adc = (ADCName)pinmap_peripheral(pin, PinMap_ADC); |
sahilmgandhi | 18:6a4db94011d3 | 66 | MBED_ASSERT(obj->adc != (ADCName)NC); |
sahilmgandhi | 18:6a4db94011d3 | 67 | obj->pin = pin; |
sahilmgandhi | 18:6a4db94011d3 | 68 | obj->pin_number = pin-600; |
sahilmgandhi | 18:6a4db94011d3 | 69 | obj->address = (0x0000 | (pin-600)); |
sahilmgandhi | 18:6a4db94011d3 | 70 | |
sahilmgandhi | 18:6a4db94011d3 | 71 | SPIName adc_mosi = (SPIName)pinmap_peripheral(ADC_MOSI, PinMap_SPI_MOSI); |
sahilmgandhi | 18:6a4db94011d3 | 72 | SPIName adc_miso = (SPIName)pinmap_peripheral(ADC_MISO, PinMap_SPI_MISO); |
sahilmgandhi | 18:6a4db94011d3 | 73 | SPIName adc_sclk = (SPIName)pinmap_peripheral(ADC_SCLK, PinMap_SPI_SCLK); |
sahilmgandhi | 18:6a4db94011d3 | 74 | SPIName adc_ssel = (SPIName)pinmap_peripheral(ADC_SSEL, PinMap_SPI_SSEL); |
sahilmgandhi | 18:6a4db94011d3 | 75 | SPIName adc_data = (SPIName)pinmap_merge(adc_mosi, adc_miso); |
sahilmgandhi | 18:6a4db94011d3 | 76 | SPIName adc_cntl = (SPIName)pinmap_merge(adc_sclk, adc_ssel); |
sahilmgandhi | 18:6a4db94011d3 | 77 | obj->adc_spi = (MPS2_SSP_TypeDef*)pinmap_merge(adc_data, adc_cntl); |
sahilmgandhi | 18:6a4db94011d3 | 78 | |
sahilmgandhi | 18:6a4db94011d3 | 79 | if(analog_spi_inited == 0){ |
sahilmgandhi | 18:6a4db94011d3 | 80 | obj->adc_spi->CR1 = 0; |
sahilmgandhi | 18:6a4db94011d3 | 81 | obj->adc_spi->CR0 = SSP_CR0_SCR_DFLT | SSP_CR0_FRF_MOT | SSP_CR0_DSS_16; |
sahilmgandhi | 18:6a4db94011d3 | 82 | obj->adc_spi->CPSR = SSP_CPSR_DFLT; |
sahilmgandhi | 18:6a4db94011d3 | 83 | obj->adc_spi->IMSC = 0x8; |
sahilmgandhi | 18:6a4db94011d3 | 84 | obj->adc_spi->DMACR = 0; |
sahilmgandhi | 18:6a4db94011d3 | 85 | obj->adc_spi->CR1 = SSP_CR1_SSE_Msk; |
sahilmgandhi | 18:6a4db94011d3 | 86 | obj->adc_spi->ICR = 0x3; |
sahilmgandhi | 18:6a4db94011d3 | 87 | analog_spi_inited = 1; |
sahilmgandhi | 18:6a4db94011d3 | 88 | } |
sahilmgandhi | 18:6a4db94011d3 | 89 | |
sahilmgandhi | 18:6a4db94011d3 | 90 | pinmap_pinout(ADC_MOSI, PinMap_SPI_MOSI); |
sahilmgandhi | 18:6a4db94011d3 | 91 | pinmap_pinout(ADC_MISO, PinMap_SPI_MISO); |
sahilmgandhi | 18:6a4db94011d3 | 92 | pinmap_pinout(ADC_SCLK, PinMap_SPI_SCLK); |
sahilmgandhi | 18:6a4db94011d3 | 93 | pinmap_pinout(ADC_SSEL, PinMap_SPI_SSEL); |
sahilmgandhi | 18:6a4db94011d3 | 94 | pinmap_pinout(pin, PinMap_ADC); |
sahilmgandhi | 18:6a4db94011d3 | 95 | } |
sahilmgandhi | 18:6a4db94011d3 | 96 | |
sahilmgandhi | 18:6a4db94011d3 | 97 | static inline uint32_t adc_read(analogin_t *obj) { |
sahilmgandhi | 18:6a4db94011d3 | 98 | return 0; |
sahilmgandhi | 18:6a4db94011d3 | 99 | } |
sahilmgandhi | 18:6a4db94011d3 | 100 | |
sahilmgandhi | 18:6a4db94011d3 | 101 | |
sahilmgandhi | 18:6a4db94011d3 | 102 | float analogin_read(analogin_t *obj) { |
sahilmgandhi | 18:6a4db94011d3 | 103 | uint32_t value = adc_read(obj); |
sahilmgandhi | 18:6a4db94011d3 | 104 | return 0; |
sahilmgandhi | 18:6a4db94011d3 | 105 | } |
sahilmgandhi | 18:6a4db94011d3 | 106 | |
sahilmgandhi | 18:6a4db94011d3 | 107 | uint16_t analogin_read_u16(analogin_t *obj) { |
sahilmgandhi | 18:6a4db94011d3 | 108 | return 0; |
sahilmgandhi | 18:6a4db94011d3 | 109 | } |
sahilmgandhi | 18:6a4db94011d3 | 110 |