Created
February 23, 2018 00:16
-
-
Save jacobrosenthal/210285b913dc89c769786d5b6bfc9fa1 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
/** | |
* Licensed to the Apache Software Foundation (ASF) under one | |
* or more contributor license agreements. See the NOTICE file | |
* distributed with this work for additional information | |
* regarding copyright ownership. The ASF licenses this file | |
* to you under the Apache License, Version 2.0 (the | |
* "License"); you may not use this file except in compliance | |
* with the License. You may obtain a copy of the License at | |
* | |
* http://www.apache.org/licenses/LICENSE-2.0 | |
* | |
* Unless required by applicable law or agreed to in writing, | |
* software distributed under the License is distributed on an | |
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | |
* KIND, either express or implied. See the License for the | |
* specific language governing permissions and limitations | |
* under the License. | |
*/ | |
#include "syscfg/syscfg.h" | |
#include "sysinit/sysinit.h" | |
#include <os/os.h> | |
#include <pwm/pwm.h> | |
#include <bsp/bsp.h> | |
#include <easing/easing.h> | |
struct pwm_dev *pwm; | |
static struct os_callout my_callout; | |
// max supposed to be 65535, but were not getting anything above ~50000 ?? | |
#define MAX_VALUE 50000 | |
#define MAX_STEPS 300 | |
// Im able to see SOME light event at like.. 5 so just start at 0 | |
static volatile int32_t step = 0; | |
static void pwm_handler() | |
{ | |
// TODO Need this to be a one shot mode, so we dont have to ease out/manually disable duty cycle and turn off timer | |
if(step<=MAX_STEPS){ | |
int32_t eased = bounce_int_out(step++, MAX_STEPS, MAX_VALUE); | |
pwm_enable_duty_cycle(pwm, 0, eased); | |
} | |
} | |
static void | |
pwm_toggle(struct os_event *ev) | |
{ | |
step=0; | |
os_callout_reset(&my_callout, OS_TICKS_PER_SEC); | |
} | |
int | |
main(int argc, char **argv) | |
{ | |
int rc; | |
sysinit(); | |
struct pwm_chan_cfg chan_conf = { | |
.pin = LED_BLINK_PIN, | |
.inverted = true, | |
.data = pwm_handler | |
}; | |
#if MYNEWT_VAL(SOFT_PWM) | |
pwm = (struct pwm_dev *) os_dev_open("spwm", 0, NULL); | |
#else | |
pwm = (struct pwm_dev *) os_dev_open("pwm0", 0, NULL); | |
#endif | |
/* set the PWM frequency */ | |
pwm_set_frequency(pwm, MAX_STEPS); | |
/* setup led 1 - 100% duty cycle*/ | |
rc = pwm_chan_config(pwm, 0, &chan_conf); | |
assert(rc == 0); | |
rc = pwm_enable_duty_cycle(pwm, 0, 0); | |
assert(rc == 0); | |
os_callout_init(&my_callout, os_eventq_dflt_get(), | |
pwm_toggle, NULL); | |
pwm_toggle(NULL); | |
while (1) { | |
os_eventq_run(os_eventq_dflt_get()); | |
} | |
assert(0); | |
return(0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment