Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: UITDSP_ADDA_Example UIT2_MovingAv_Intr UIT2_VariableFIR UIT2_VowelSynthesizer ... more
TIM4_SlaveSelect.hpp
00001 //-------------------------------------------------------------- 00002 // Class for generate SPI slave select using TIM4 00003 // 00004 // PB_6 (D10), PB_7, PB_8 (D15), and PB_9 (D14) can be used 00005 // 2015/03/31, Copyright (c) 2015 MIKAMI, Naoki 00006 //-------------------------------------------------------------- 00007 00008 #ifndef TIM4_SLAVESELECT_HPP 00009 #define TIM4_SLAVESELECT_HPP 00010 00011 #include "mbed.h" 00012 00013 namespace Mikami 00014 { 00015 class TIM4_SlaveSelect 00016 { 00017 public: 00018 TIM4_SlaveSelect( 00019 uint16_t psc, // prescaler 00020 uint16_t arr, // auto-reload register 00021 PinName pin) // pin name 00022 : myTim_(TIM4) 00023 { 00024 if ( (pin != PB_6) && (pin != PB_7) 00025 &&(pin != PB_8) && (pin != PB_9) ) 00026 { 00027 fprintf(stderr, "\r\nIllegal pin name in TIM4_SlaveSelect\r\n"); 00028 while (true) {} 00029 } 00030 00031 PwmOut css(pin); // for slave select 00032 myTim_->CR1 |= TIM_CR1_OPM; // one-pulse mode 00033 myTim_->PSC = psc; // prescaler 00034 myTim_->ARR = arr; // pulse width 00035 if (pin == PB_6) myTim_->CCR1 = 1; 00036 if (pin == PB_7) myTim_->CCR2 = 1; 00037 if (pin == PB_8) myTim_->CCR3 = 1; 00038 if (pin == PB_9) myTim_->CCR4 = 1; 00039 } 00040 00041 // Generate slave select 00042 void SlaveSelect() 00043 { 00044 myTim_->CNT = 1; // Set counter 1 00045 myTim_->CR1 |= TIM_CR1_CEN; // Enable TIM4 00046 } 00047 00048 private: 00049 TIM_TypeDef* const myTim_; 00050 00051 // Forbid to use copy constructor 00052 TIM4_SlaveSelect(const TIM4_SlaveSelect&); 00053 // Forbid to use substitution operator 00054 TIM4_SlaveSelect operator=(const TIM4_SlaveSelect&); 00055 }; 00056 } 00057 #endif // TIM4_SLAVESELECT_HPP
Generated on Sun Jul 17 2022 05:45:25 by
1.7.2