| 2410 | |
| 2411 | |
| 2412 | void pwmWrite (int pin, int value) |
| 2413 | { |
| 2414 | struct wiringPiNodeStruct *node = wiringPiNodes ; |
| 2415 | |
| 2416 | setupCheck ("pwmWrite") ; |
| 2417 | |
| 2418 | if ((pin & PI_GPIO_MASK) == 0) // On-Board Pin |
| 2419 | { |
| 2420 | if (!ToBCMPin(&pin)) { |
| 2421 | return; |
| 2422 | } |
| 2423 | |
| 2424 | /* would be possible on ms mode but not on bal, deactivated, use pwmc modify instead |
| 2425 | if (piGpioBase == GPIO_PERI_BASE_2711) { |
| 2426 | value = (OSC_FREQ_BCM2711*value)/OSC_FREQ_DEFAULT; |
| 2427 | } |
| 2428 | */ |
| 2429 | usingGpioMemCheck ("pwmWrite") ; |
| 2430 | int channel = gpioToPwmPort[pin]; |
| 2431 | int readback = 0x00; |
| 2432 | if (piRP1Model()) { |
| 2433 | if (channel>=0 && channel<=3) { |
| 2434 | unsigned int addr = RP1_PWM0_CHAN_START+RP1_PWM0_CHAN_OFFSET*channel+RP1_PWM0_CHAN_DUTY; |
| 2435 | pwm[addr] = value; |
| 2436 | readback = pwm[addr]; |
| 2437 | } else { |
| 2438 | fprintf(stderr, "pwmWrite: invalid channel at GPIO pin %d \n", pin); |
| 2439 | } |
| 2440 | } else { |
| 2441 | *(pwm + channel) = value ; |
| 2442 | readback = *(pwm + channel); |
| 2443 | } |
| 2444 | if (wiringPiDebug) { |
| 2445 | printf ("PWM value(duty): %u. Current register: 0x%08X\n", value, readback); |
| 2446 | } |
| 2447 | } |
| 2448 | else |
| 2449 | { |
| 2450 | if ((node = wiringPiFindNode (pin)) != NULL) |
| 2451 | node->pwmWrite (node, pin, value) ; |
| 2452 | } |
| 2453 | } |
| 2454 | |
| 2455 | |
| 2456 | /* |