diff --git a/os/src/driver/gpio/led.rs b/os/src/driver/gpio/led.rs index 6fa12ed..10d43c5 100644 --- a/os/src/driver/gpio/led.rs +++ b/os/src/driver/gpio/led.rs @@ -5,6 +5,7 @@ use k210_soc::{ pub fn init() { // led b 映射到 gpiohs 0 + // io::LED_B 为物理 pin fpioa::set_function(io::LED_B, fpioa::function::GPIOHS0); // gpiohs 设置 0 为输出 gpiohs::set_direction(0, gpio::direction::OUTPUT); diff --git a/os/src/driver/gpio/led_ex.rs b/os/src/driver/gpio/led_ex.rs index b632f7e..037954e 100644 --- a/os/src/driver/gpio/led_ex.rs +++ b/os/src/driver/gpio/led_ex.rs @@ -1 +1,23 @@ -// 外部的 led \ No newline at end of file +// 外部的 led + +use k210_soc::{ + fpioa::{self, io}, + gpio, gpiohs, +}; + +pub fn init() { + // led b 映射到 gpiohs 0 + // 9 + fpioa::set_function(io::BPSK_P, fpioa::function::GPIOHS0); + // 10 + fpioa::set_function(io::BPSK_N, fpioa::function::GPIOHS1); + // gpiohs 设置 0 为输出 + gpiohs::set_direction(0, gpio::direction::OUTPUT); + gpiohs::set_direction(1, gpio::direction::OUTPUT); + + gpiohs::set_pin(0, false); + gpiohs::set_pin(1, true); + + println!("0 is {}", gpiohs::get_pin(0)); + println!("1 is {}", gpiohs::get_pin(1)); +} diff --git a/os/src/driver/gpio/led_gpio.rs b/os/src/driver/gpio/led_gpio.rs index e69de29..e538879 100644 --- a/os/src/driver/gpio/led_gpio.rs +++ b/os/src/driver/gpio/led_gpio.rs @@ -0,0 +1,14 @@ +use k210_soc::{ + fpioa::{self, io}, + gpio, gpiohs, +}; + +pub fn init() { + // led b 映射到 gpiohs 0 + fpioa::set_function(io::LED_R, fpioa::function::GPIOHS5); + // gpiohs 设置 0 为输出 + gpiohs::set_direction(5, gpio::direction::OUTPUT); + // gpiohs 0 为 false , false 为点亮 + gpiohs::set_pin(5, false); + println!("0 is {}", gpiohs::get_pin(5)); +} diff --git a/os/src/driver/gpio/mod.rs b/os/src/driver/gpio/mod.rs index 53c0d72..a5cbeb3 100644 --- a/os/src/driver/gpio/mod.rs +++ b/os/src/driver/gpio/mod.rs @@ -1,4 +1,4 @@ -mod led; +mod led_ex; pub fn init() { - led::init(); + led_ex::init(); }