summaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs37
1 files changed, 33 insertions, 4 deletions
diff --git a/src/main.rs b/src/main.rs
index 168e55a..6690828 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -2,7 +2,7 @@
#[macro_use] extern crate stm32f103xx;
extern crate cortex_m;
-use stm32f103xx::{GPIOA, RCC, SYST, I2C1};
+use stm32f103xx::{GPIOA, GPIOB, RCC, SYST, I2C1};
use cortex_m::peripheral::SystClkSource;
mod i2c;
mod ds3231;
@@ -23,6 +23,7 @@ fn systick_handler() {
SR.as_mut().unwrap().output_bits(N as u32);
N += 1;
*/
+ /*
SR.as_mut().unwrap().output_bits(digits2bcds(&DIGITS[..]));
let mut i = 0;
let mut carry = 1;
@@ -31,10 +32,16 @@ fn systick_handler() {
carry = if DIGITS[i] > 9 {DIGITS[i] = 0; 1} else {0};
i += 1;
}
+ */
+ let ds3231::Date{second: sec, minute: min, hour: hr, ..} = RTC.as_mut().unwrap().read_fulldate();
+ DIGITS[4] = sec / 10; DIGITS[5] = sec % 10;
+ DIGITS[2] = min / 10; DIGITS[3] = min % 10;
+ DIGITS[0] = hr / 10; DIGITS[1] = hr % 10;
+ SR.as_mut().unwrap().output_bits(digits2bcds(&DIGITS[..]));
}
}
-//exception!(SYS_TICK, systick_handler);
+exception!(SYS_TICK, systick_handler);
impl<'a> ShiftRegister<'a> {
fn new(g: &'a stm32f103xx::gpioa::RegisterBlock,
@@ -73,6 +80,7 @@ fn digits2bcds(digs: &[u8]) -> u32 {
fn main() {
let gpioa: &stm32f103xx::gpioa::RegisterBlock = unsafe { &*GPIOA.get() };
+ let gpiob: &stm32f103xx::gpioa::RegisterBlock = unsafe { &*GPIOB.get() };
let rcc: &stm32f103xx::rcc::RegisterBlock = unsafe { &*RCC.get() };
let i2c: &stm32f103xx::i2c1::RegisterBlock = unsafe { &*I2C1.get() };
let syst: &cortex_m::peripheral::SYST = unsafe { &*SYST.get() };
@@ -81,16 +89,37 @@ fn main() {
syst.set_reload(100_000);
syst.enable_interrupt();
syst.enable_counter();
- rcc.apb2enr.modify(|_, w| w.iopaen().enabled());
+ rcc.apb2enr.modify(|_, w| w.iopaen().enabled()
+ .iopben().enabled()
+ .afioen().enabled());
gpioa.crl.modify(|_, w|
w.mode0().output().cnf0().push()
.mode1().output().cnf1().push()
.mode2().output().cnf2().push());
+ gpiob.crl.modify(|_, w|
+ w.mode6().output50().cnf6().alt_open()
+ .mode7().output50().cnf7().alt_open());
+
+ rcc.apb1enr.modify(|_, w| w.i2c1en().enabled());
+
unsafe {
RTC = Some(ds3231::DS3231::new(i2c));
SR = Some(ShiftRegister::new(gpioa, 24));
SR.as_mut().unwrap().output_bits(0);
- let t = RTC.as_mut().unwrap().read_fulldate();
+ let rtc = RTC.as_mut().unwrap();
+ rtc.init();
+ let x = rtc.read_fulldate();
+ /*
+ rtc.write_fulldate(&ds3231::Date{second: 30,
+ minute: 48,
+ hour: 21,
+ day: 4,
+ date: 21,
+ month: 9,
+ year: 17,
+ am: false,
+ am_enable: false});
+ */
}
}