diff --git a/src/main.c b/src/main.c index bf2beeef018144a9f5da3e90bec6760d2e0ce192..046ef8babe7c794e15154896d851538016bb9d49 100644 --- a/src/main.c +++ b/src/main.c @@ -2,7 +2,7 @@ #include <hardware/i2c.h> #include <stdio.h> #include <unistd.h> - +#include "hardware/pwm.h" const uint8_t init[4] = {0x21, 0xa0, 0xe1, 0x81}; const uint8_t zeile[8] = {0x00, 0x02, 0x04, 0x06, 0x08, 0x10, 0x12, 0x14}; const uint8_t fill[17] = {0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; @@ -104,6 +104,27 @@ const uint8_t better_matrix[65][17] = { {0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0b01111111, 0x00}, {0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0b11111111, 0x00}, }; + +void set_progress(int percentage) +{ + int numerator = (percentage * 32) / 100; + + for (int i = 0; i <= numerator; i++) + { + i2c_write_blocking(i2c_default, 0x70, better_matrix[i], 17, false); + // sleep + // for (int j = 0; j < 100000; j++) + // { + // volatile int i = 0; + // } + } +} +int a = 0; + +void callback() +{ + a = 1; +} int main() { // clock enable: 100000 baud (bit/s) @@ -130,27 +151,33 @@ int main() i2c_write_blocking(i2c_default, 0x70, empty, 17, false); - for (int i = 0; i <= 64; i++) - { - i2c_write_blocking(i2c_default, 0x70, better_matrix[i], 17, false); + set_progress(200); + set_progress(30); - // sleep - for (int j = 0; j < 1000000; j++) - { - volatile int i = 0; - } - } + gpio_set_function(28, GPIO_FUNC_PWM); - for (int i = 64; i >= 0; i--) - { - i2c_write_blocking(i2c_default, 0x70, better_matrix[i], 17, false); + uint slice_num = pwm_gpio_to_slice_num(28); - // sleep - for (int j = 0; j < 1000000; j++) - { - volatile int i = 0; - } - } + // 133 Mhz / 133 = 1 Mhz => 1 cycle = 1 us + // 10 mikrosekunden + pwm_set_clkdiv(slice_num, 133); + pwm_set_wrap(slice_num, 65000); + pwm_set_chan_level(slice_num, PWM_CHAN_A, 10); + pwm_set_enabled(slice_num, true); + + uint test = 500; + set_progress(0); + + uint another_slice_num = pwm_gpio_to_slice_num(27); + // 65000 * 133 * 10^6 10 meters + // 65000 max cycles + pwm_set_clkdiv(another_slice_num, 133); + pwm_set_wrap(another_slice_num, 65000); + pwm_set_clkdiv_mode(another_slice_num, PWM_DIV_B_HIGH); + pwm_set_enabled(slice_num, true); + int b = 7; + gpio_set_irq_enabled_with_callback(27, GPIO_IRQ_EDGE_FALL, true, callback); + set_progress(100); return 0; } \ No newline at end of file