]> code.bitgloo.com Git - clyne/stm-game.git/commitdiff
fix power settings; rand() for flapbird
authorClyne Sullivan <clyne@bitgloo.com>
Sat, 11 Jun 2022 16:41:56 +0000 (12:41 -0400)
committerClyne Sullivan <clyne@bitgloo.com>
Sat, 11 Jun 2022 16:41:56 +0000 (12:41 -0400)
cfg/mcuconf.h
openocd.sh
source/flapbird.c
source/main.c

index 96e9080b5e19b7cc6a309f81d819e9e413527be9..dc36c84be3f1680e01b056db54b3cd7a3bd15ad3 100644 (file)
@@ -39,7 +39,7 @@
  * HAL driver system settings.\r
  */\r
 #define STM32_NO_INIT                       FALSE\r
-#define STM32_VOS                           STM32_VOS_1P2\r
+#define STM32_VOS                           STM32_VOS_1P5\r
 #define STM32_PVD_ENABLE                    TRUE\r
 #define STM32_PLS                           STM32_PLS_LEV4\r
 #define STM32_HSI16_ENABLED                 TRUE\r
@@ -50,9 +50,9 @@
 #define STM32_ADC_CLOCK_ENABLED             TRUE\r
 #define STM32_MSIRANGE                      STM32_MSIRANGE_4M\r
 #define STM32_SW                            STM32_SW_MSI\r
-#define STM32_PLLSRC                        STM32_PLLSRC_NONE\r
-#define STM32_PLLMUL_VALUE                  1\r
-#define STM32_PLLDIV_VALUE                  8\r
+#define STM32_PLLSRC                        STM32_PLLSRC_HSI16\r
+#define STM32_PLLMUL_VALUE                  3\r
+#define STM32_PLLDIV_VALUE                  3\r
 #define STM32_HPRE                          STM32_HPRE_DIV1\r
 #define STM32_PPRE1                         STM32_PPRE1_DIV1\r
 #define STM32_PPRE2                         STM32_PPRE2_DIV1\r
index 1ce7e72b09984232cfb136cb6f9d828ef4a6afa0..28d46ca951035775c5b909cb48e7f4c8992d90eb 100755 (executable)
@@ -1 +1 @@
-openocd -f /usr/local/share/openocd/scripts/interface/stlink-v2.cfg -f /usr/local/share/openocd/scripts/target/stm32l0.cfg -c "init; program build/ch.hex verify reset exit"
+openocd -f /usr/share/openocd/scripts/interface/stlink-v2.cfg -f /usr/share/openocd/scripts/target/stm32l0.cfg -c "init; program build/ch.hex verify reset exit"
index f2dd2cf7452ce6c87306d3217a305daf5a24588d..800e89280dfdd9a9b9d88d68f498071cbfd9fa15 100644 (file)
@@ -1,5 +1,8 @@
 #include "buttons.h"
 #include "dogs.h"
+#include "hal.h"
+
+#include <stdint.h>
 
 static const unsigned char bird[] = {
     8, 8,
@@ -20,11 +23,23 @@ static int py;
 static int vy;
 static int counter;
 
+static uint32_t next = 31415926;
+
+int rand()
+{
+    uint32_t tr = RTC->TR;
+    uint32_t dr = RTC->DR;
+    next = next * (0x197244 + dr) + tr;
+    return (unsigned int)(next / 65536) % 32768;
+}
+
+#define NEW_BAR()      (rand() % 50 + 5)
+
 void flapbird_init()
 {
     score = 0;
-    t1x = DISP_WIDTH / 2, t1o = 15;
-    t2x = DISP_WIDTH, t2o = 49;
+    t1x = DISP_WIDTH / 2, t1o = NEW_BAR();
+    t2x = DISP_WIDTH, t2o = NEW_BAR();
     py = DISP_HEIGHT / 2 - 4;
     vy = 0;
     counter = 0;
@@ -69,11 +84,16 @@ int flapbird_loop()
         score = (py + 2 > t2o - 10 && py + 6 < t2o + 10) ? score + 1 : 0;
 
     t1x -= 2;
-    if (t1x <= -5)
+    if (t1x <= -5) {
         t1x = DISP_WIDTH;
+       t1o = NEW_BAR();
+    }
+
     t2x -= 2;
-    if (t2x <= -5)
+    if (t2x <= -5) {
         t2x = DISP_WIDTH;
+       t2o = NEW_BAR();
+    }
 
     return 100;
 }
index fd753ead64b65a8b10903f15ba6561273957d19b..89f3cf0c43d8598fe7d8fdc7047eea34900588da 100644 (file)
@@ -67,6 +67,9 @@ static void alarm_callback(RTCDriver *rtcp, rtcevent_t event)
 int main(void)
 {
     halInit();
+
+    RCC->CR &= ~(RCC_CR_PLLON); // Ensure that the PLL is off (unused).
+
     //chSysInit();
     buttons_init();