<commit_before>//
//  GPTimer.h
//  Bedrock
//
//  Created by <NAME> on 2016-01-17.
//  Copyright © 2016 EricYanush. All rights reserved.
//

#ifndef GPTimer_h
#define GPTimer_h

#include "types.hpp"

namespace Bedrock {
    template <typename width_t>
    class GPTimer {
    public:
        
        void setPrescaler(uint16_t prescaler) {
            PSC = prescaler;
        }

        uint16_t getPrescaler() {
            return (uint16_t)PSC;
        }

        void setReload(width_t reloadVal) {
            ARR = reloadVal;
        }

        width_t getReload() {
            return ARR;
        }
        
        width_t getCount() {
            return (width_t)CNT;
        }
        
        void enable() {
            CR1 |= 0x1;
        }
        
        void disable() {
            CR1 &= ~(0x1);
        }

        bool isEnabled() {
            return (CR1 & ENABLE) == ENABLE;
        }

        void enableUpdateInterrupt() {
            DIER |= (ENABLE << 0);
        }

        void disableUpdateInterrupt() {
            DIER &= ~(ENABLE << 0);
        }

        bool isUpdateInterruptEnabled() {
            return (DIER & ENABLE) == ENABLE;
        }

        bool isUpdateInterruptPending() {
            return (SR & 0x1) == 0x1;
        }

        void ackUpdate() {
            SR &= ~(1 << 0);
        }
        
        void ackTrigger() {
            SR &= ~(1 << 6);
        }
        
        enum class CapCompSelection : uint8_t
        {
            OUTPUT = 0b00,
            IN_DEF = 0b01,
            IN_ALT = 0b10,
            IN_TRC = 0b11
        };
        
        void setCapCompSelection(uint8_t channel, CapCompSelection sel)
        {
            uint8_t regIndex = channel/3;
            uint8_t bitOffset = ((channel - 1) % 2) * 8;
            
            CCMR[regIndex] &= ~(0b11 << bitOffset);
            CCMR[regIndex] |= static_cast<uint8_t>(sel) << bitOffset;
        }
        
        void enableCapCompChannel(uint8_t channel)
        {
            uint8_t bitOffset = (channel - 1) * 4;
            CCER |= (ENABLE << bitOffset);
        }
        
        void disableCapCompChannel(uint8_t channel)
        {
            uint8_t bitOffset = (channel - 1) * 4;
            CCER &= ~(ENABLE << bitOffset);
        }
        
        width_t readInputCaptureChannel(uint8_t channel)
        {
            return CCR[channel];
        }
        
        void enableCaptureEvent(uint8_t channel)
        {<commit_msg>Add capture compare output mode methods to GPTimer (PWM output)<commit_after>//
//  GPTimer.h
//  Bedrock
//
//  Created by <NAME> on 2016-01-17.
//  Copyright © 2016 EricYanush. All rights reserved.
//

#ifndef GPTimer_h
#define GPTimer_h

#include "types.hpp"

namespace Bedrock {
    template <typename width_t>
    class GPTimer {
    public:
        
        void setPrescaler(uint16_t prescaler) {
            PSC = prescaler;
        }

        uint16_t getPrescaler() {
            return (uint16_t)PSC;
        }

        void setReload(width_t reloadVal) {
            ARR = reloadVal;
        }

        width_t getReload() {
            return ARR;
        }
        
        width_t getCount() {
            return (width_t)CNT;
        }
        
        void enable() {
            CR1 |= 0x1;
        }
        
        void disable() {
            CR1 &= ~(0x1);
        }

        bool isEnabled() {
            return (CR1 & ENABLE) == ENABLE;
        }

        void enableUpdateInterrupt() {
            DIER |= (ENABLE << 0);
        }

        void disableUpdateInterrupt() {
            DIER &= ~(ENABLE << 0);
        }

        bool isUpdateInterruptEnabled() {
            return (DIER & ENABLE) == ENABLE;
        }

        bool isUpdateInterruptPending() {
            return (SR & 0x1) == 0x1;
        }

        void ackUpdate() {
            SR &= ~(1 << 0);
        }
        
        void ackTrigger() {
            SR &= ~(1 << 6);
        }
        
        enum class CapCompSelection : uint8_t
        {
            OUTPUT = 0b00,
            IN_DEF = 0b01,
            IN_ALT = 0b10,
            IN_TRC = 0b11
        };
        
        void setCapCompSelection(uint8_t channel, CapCompSelection sel)
        {
            uint8_t regIndex = channel/3;
            uint8_t bitOffset = ((channel - 1) % 2) * 8;
            
            CCMR[regIndex] &= ~(0b11 << bitOffset);
            CCMR[regIndex] |= static_cast<uint8_t>(sel) << bitOffset;
        }
        
        enum class OutputCompareMode : uint8_t
        {
            Frozen        = 0b000,
            MatchActive   = 0b001,
            MatchInactive = 0b010,
            Toggle        = 0b011,
            ForceInactive = 0b100,
            ForceActive   = 0b101,
            PWMMode1      = 0b110,
            PWMMode2      = 0b111
        };
        
        void setOuputCompareMode(uint8_t channel, OutputCompareMode mode)
        {
            uint8_t regIndex = channel/3;
            uint8_t bitOffset = (((channel - 1) % 2) * 8) + 4;
            
            CCMR[regIndex] &= ~(0b111 << bitOffset);
            CCMR[regIndex] |= static_cast<uint8_t>(mode) << bitOffset;
        }
        
        void setCapCompVal(uint8_t channel, width_t val)
        {
            CCR[channel - 1] = val;
        }
        
        void enableCapCompChannel(uint8_t channel)
        {
            uint8_t bitOffset = (channel - 1) * 4;
            CCER |= (ENABLE << bitOffset);
        }
        
        void disableCapCompChannel(uint8_t channel)
        {
            uint8_t bitOffset = (channel - 1) * 4;
            CCER &= ~(ENABLE << bitOffset);
        }
        
        width_t readInputCaptureChannel(uint8_t channel)
        {
            return CCR[channel];
        }
        
        void enableCaptureEvent(uint8_t channel)
        {
{'fraction_non_alphanumeric': 0.10005139626520473, 'fraction_numerical': 0.032208326194963166, 'mean_word_length': 1.2654249126891735, 'pattern_counts': {'":': 0, '<': 46, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2086815', 'n_tokens_mistral': 1917, 'n_tokens_neox': 1780, 'n_words': 376}