MCPcopy Create free account
hub / github.com/WiringPi/WiringPi / softPwmCreate

Function softPwmCreate

wiringPi/softPwm.c:125–163  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

123 */
124
125int softPwmCreate (int pin, int initialValue, int pwmRange)
126{
127 int res ;
128 pthread_t myThread ;
129 int *passPin ;
130
131 if (pin >= MAX_PINS)
132 return -1 ;
133
134 if (range [pin] != 0) // Already running on this pin
135 return -1 ;
136
137 if (pwmRange <= 0)
138 return -1 ;
139
140 passPin = malloc (sizeof (*passPin)) ;
141 if (passPin == NULL)
142 return -1 ;
143
144 digitalWrite (pin, LOW) ;
145 pinMode (pin, OUTPUT) ;
146
147 marks [pin] = initialValue ;
148 range [pin] = pwmRange ;
149
150 *passPin = pin ;
151 newPin = pin ;
152 res = pthread_create (&myThread, NULL, softPwmThread, (void *)passPin) ;
153
154 if (res != 0)
155 return res ;
156
157 while (newPin != -1)
158 delay (1) ;
159
160 threads [pin] = myThread ;
161
162 return res ;
163}
164
165
166/*

Callers 4

pinModeFunction · 0.85
mainFunction · 0.85
mainFunction · 0.85
mainFunction · 0.85

Calls 3

digitalWriteFunction · 0.85
pinModeFunction · 0.85
delayFunction · 0.70

Tested by

no test coverage detected