不韋 呂 / UITDSP_ADDA

Dependents:   UITDSP_ADDA_Example UIT2_MovingAv_Intr UIT2_VariableFIR UIT2_VowelSynthesizer ... more

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers ADC_Interrupt.hpp Source File

ADC_Interrupt.hpp

00001 //------------------------------------------------------
00002 // Derived class of ADC_Base for use interrupt
00003 //
00004 // 2015/04/19, Copyright (c) 2015 MIKAMI, Naoki
00005 //------------------------------------------------------
00006 
00007 #ifndef ADC_INTERRUPT_HPP
00008 #define ADC_INTERRUPT_HPP
00009 
00010 #include "ADC_BuiltIn.hpp"
00011 
00012 namespace Mikami
00013 {
00014     class ADC_Intr : public ADC_BuiltIn
00015     {
00016     private:       
00017         // for inhibition of copy constructor
00018         ADC_Intr(const ADC_Intr&);
00019         // for inhibition of substitute operator
00020         ADC_Intr& operator=(const ADC_Intr&);
00021 
00022     public:
00023         ADC_Intr(PinName pin1, int frequency,
00024                  PinName pin2 = NC, PinName pin3 = NC)
00025             : ADC_BuiltIn(pin1, frequency, pin2, pin3)
00026         { myAdc_->CR1 |= ADC_CR1_EOCIE; }   // Interrupt enable
00027 
00028         // Set interrupt vector and enable IRQ of ADC
00029         void SetIntrVec(void (*Func)())
00030         {
00031             NVIC_SetVector(ADC_IRQn, (uint32_t)Func);   // See "cmsis_nvic.h"
00032             NVIC_EnableIRQ(ADC_IRQn);                   // See "core_cm4.h"
00033         }       
00034 
00035         // Read ADC, range: [0, 0x0FFF]
00036         virtual uint16_t Read_u16()
00037         { return myAdc_->DR; }
00038 
00039         // Read ADC, range: [0, 0x0FFF]
00040         virtual uint16_t ReadWait_u16()
00041         {
00042             WaitDone();
00043             return myAdc_->DR;
00044         }
00045 
00046         // Read ADC, range: [-1.0f, 1.0f]
00047         virtual float Read()
00048         { return AMP_*((int16_t)myAdc_->DR - 2048); }
00049         
00050         // Clear pending IRQ and enable IRQ
00051         void ClearPending_EnableIRQ()
00052         {
00053             NVIC_ClearPendingIRQ(ADC_IRQn);
00054             NVIC_EnableIRQ(ADC_IRQn);
00055         }
00056 
00057         // Software start with disable IRQ
00058         void SoftStart()
00059         {
00060             NVIC_DisableIRQ(ADC_IRQn);
00061             myAdc_->CR2 |= ADC_CR2_SWSTART;
00062         }        
00063     };
00064 }
00065 #endif  // ADC_INTERRUPT_HPP