pwm.c
Go to the documentation of this file.
1 /*
2  * pwm.c
3  *
4  * Copyright (c) 2014 Jeremy Garff <jer @ jers.net>
5  *
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without modification, are permitted
9  * provided that the following conditions are met:
10  *
11  * 1. Redistributions of source code must retain the above copyright notice, this list of
12  * conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright notice, this list
14  * of conditions and the following disclaimer in the documentation and/or other materials
15  * provided with the distribution.
16  * 3. Neither the name of the owner nor the names of its contributors may be used to endorse
17  * or promote products derived from this software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
20  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
21  * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE
22  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
24  * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
26  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  *
28  */
29 
30 
31 #include <stdint.h>
32 
33 #include "ws2811.h"
34 
35 #include "pwm.h"
36 
37 
38 // Mapping of Pin to alternate function for PWM channel 0
40 {
41  {
42  .pinnum = 12,
43  .altnum = 0,
44  },
45  {
46  .pinnum = 18,
47  .altnum = 5,
48  },
49  {
50  .pinnum = 40,
51  .altnum = 0,
52  },
53 };
54 
55 // Mapping of Pin to alternate function for PWM channel 1
57 {
58  {
59  .pinnum = 13,
60  .altnum = 0,
61  },
62  {
63  .pinnum = 19,
64  .altnum = 5,
65  },
66  {
67  .pinnum = 41,
68  .altnum = 0,
69  },
70  {
71  .pinnum = 45,
72  .altnum = 0,
73  },
74 };
75 
77 {
78  {
80  .count = sizeof(pwm_pin_chan0) / sizeof(pwm_pin_chan0[0]),
81  },
82  {
83  .pins = pwm_pin_chan1,
84  .count = sizeof(pwm_pin_chan1) / sizeof(pwm_pin_chan1[0]),
85  },
86 };
87 
88 
89 int pwm_pin_alt(int chan, int pinnum)
90 {
91  const pwm_pin_tables_t *pintable = &pwm_pin_tables[chan];
92  int i;
93 
94  for (i = 0; i < pintable->count; i++)
95  {
96  if (pintable->pins[i].pinnum == pinnum)
97  {
98  return pintable->pins[i].altnum;
99  }
100  }
101 
102  return -1;
103 }
104 
const pwm_pin_table_t pwm_pin_chan1[]
Definition: pwm.c:56
const pwm_pin_table_t pwm_pin_chan0[]
Definition: pwm.c:39
#define RPI_PWM_CHANNELS
Definition: pwm.h:54
const pwm_pin_tables_t pwm_pin_tables[RPI_PWM_CHANNELS]
Definition: pwm.c:76
const pwm_pin_table_t * pins
Definition: pwm.h:116
const int count
Definition: pwm.h:115
int altnum
Definition: pwm.h:110
int pwm_pin_alt(int chan, int pinnum)
Definition: pwm.c:89
int pinnum
Definition: pwm.h:109


ws281x
Author(s): Alexey Rogachevskiy , Oleg Kalachev
autogenerated on Wed Jun 15 2022 02:46:00