-
-
Save m3x1m0m/8880676254c0b323aea3b96140279b03 to your computer and use it in GitHub Desktop.
PWM FE310
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef INCLUDED_PWM | |
#define INCLUDED_PWM | |
#include <stdio.h> | |
#include <stdbool.h> | |
#include <metal/machine/platform.h> | |
// GPIO instance | |
#define GPIO_ADDR METAL_SIFIVE_GPIO0_0_BASE_ADDRESS // There is only one instance | |
// PWM instance 0 with 8 bits | |
#define PWM0_ADDR METAL_SIFIVE_PWM0_0_BASE_ADDRESS | |
// GPIO registers | |
#define GPIO_IOF_EN_ADDR(GMAX) (int*)(GMAX + METAL_SIFIVE_GPIO0_IOF_EN) | |
#define GPIO_IOF_SEL_ADDR(GMAX) (int*)(GMAX + METAL_SIFIVE_GPIO0_IOF_SEL) | |
#define GPIO_OUT_XOR(GMAX) (int*)(GMAX + METAL_SIFIVE_GPIO0_OUT_XOR) | |
// PWM registers | |
#define PWM_CFG_ADDR(PMAX) (int*)(PMAX + METAL_SIFIVE_PWM0_PWMCFG) // Config | |
#define PWM_COUNT_ADDR(PMAX) (int*)(PMAX + METAL_SIFIVE_PWM0_PWMCOUNT) // Count | |
#define PWMS_ADDR(PMAX) (int*)(PMAX + METAL_SIFIVE_PWM0_PWMS) // Scaled count | |
#define PWM_CMP_0_ADDR(PMAX) (int*)(PMAX + METAL_SIFIVE_PWM0_PWMCMP0) // Compare | |
// PWM config offsets | |
#define PWMSCALE 0 // 4 bits | |
#define PWMSTICKY 8 // 1 bit | |
#define PWMZEROCMP 9 // 1 bit | |
#define PWMDEGLITCH 10 // 1 bit | |
#define PWMENALWAYS 12 // 1 bit | |
#define PWMONESHOT 13 // 1 bit | |
#define PWM0CENTER 16 // 1 bit | |
#define PWMCMP0GANG 24 // 1 bit | |
#define PWMCMP0IP 28 // 1 bit | |
// Pin | |
int pwm_set_comp(const uint8_t comp_val); | |
int pwm_initialize(const uint8_t pwm_pin, const uint8_t comp_value, const bool xo); | |
#endif /*INCLUDED_PWM*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment