My forked repository. DISCO_F407VG, DISCO_F303VC, DISCO_F051R8 and DISCO_F100RB maybe added.
Dependents: FastPWM-DISCO-test
Fork of FastPWM by
Device/FastPWM_KLXX.cpp
- Committer:
- Sissors
- Date:
- 2014-06-27
- Revision:
- 8:a7745c791b0c
- Parent:
- 6:0f57969697b6
- Child:
- 9:c50f688cad07
File content as of revision 8:a7745c791b0c:
#ifdef TARGET_KLXX #include "FastPWM.h" void FastPWM::initFastPWM( void ) { bits = 16; } void FastPWM::pulsewidth_ticks( uint32_t ticks ) { *(_pwm.CnV) = ticks; } void FastPWM::period_ticks( uint32_t ticks ) { *(_pwm.MOD) = ticks; } uint32_t FastPWM::getPeriod( void ) { return *(_pwm.MOD); } uint32_t FastPWM::setPrescaler(uint32_t reqScale) { //Yes this is ugly, yes I should feel bad about it volatile uint32_t *TPM_SC = _pwm.MOD - 2; const char prescalers[] = {1, 2, 4, 8, 16, 32, 64, 128}; //If prescaler is 0, return current one if (reqScale == 0) return (prescalers[(*TPM_SC) & 0x07]); uint32_t retval = 0; char bin; for (bin = 0; bin<8; bin++) { retval = prescalers[bin]; if (retval >= reqScale) break; } //Clear lower 5 bits, write new value: char clockbits = *TPM_SC & (3<<3); //For some reason clearing them takes some effort while ((*TPM_SC & 0x1F) != 0) *TPM_SC &= ~0x1F; *TPM_SC |= bin + clockbits; return retval; } #endif