aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--cfg/chconf.h7
-rw-r--r--cfg/mcuconf.h16
-rw-r--r--dogs.c14
-rw-r--r--dogs.h1
-rw-r--r--main.c58
5 files changed, 68 insertions, 28 deletions
diff --git a/cfg/chconf.h b/cfg/chconf.h
index 1ad623b..dc2ccc1 100644
--- a/cfg/chconf.h
+++ b/cfg/chconf.h
@@ -451,6 +451,10 @@
* @note This macro can be used to activate a power saving mode.
*/
#define CH_CFG_IDLE_ENTER_HOOK() { \
+ RCC->ICSCR = (RCC->ICSCR & ~RCC_ICSCR_MSIRANGE_Msk); \
+ while (!(RCC->CR & RCC_CR_MSIRDY)); \
+ PWR->CR &= ~PWR_CR_LPRUN; \
+ PWR->CR |= PWR_CR_LPRUN; \
}
/**
@@ -460,6 +464,9 @@
* @note This macro can be used to deactivate a power saving mode.
*/
#define CH_CFG_IDLE_LEAVE_HOOK() { \
+ RCC->ICSCR |= 6 << RCC_ICSCR_MSIRANGE_Pos; \
+ while (!(RCC->CR & RCC_CR_MSIRDY)); \
+ PWR->CR &= ~PWR_CR_LPRUN; \
}
/**
diff --git a/cfg/mcuconf.h b/cfg/mcuconf.h
index a580925..217d13f 100644
--- a/cfg/mcuconf.h
+++ b/cfg/mcuconf.h
@@ -39,26 +39,26 @@
* HAL driver system settings.
*/
#define STM32_NO_INIT FALSE
-#define STM32_VOS STM32_VOS_1P8
-#define STM32_PVD_ENABLE FALSE
-#define STM32_PLS STM32_PLS_LEV0
+#define STM32_VOS STM32_VOS_1P2
+#define STM32_PVD_ENABLE TRUE
+#define STM32_PLS STM32_PLS_LEV4
#define STM32_HSI16_ENABLED TRUE
#define STM32_HSI16_DIVIDER_ENABLED FALSE
-#define STM32_LSI_ENABLED TRUE
+#define STM32_LSI_ENABLED FALSE
#define STM32_HSE_ENABLED FALSE
#define STM32_LSE_ENABLED FALSE
#define STM32_ADC_CLOCK_ENABLED TRUE
-#define STM32_MSIRANGE STM32_MSIRANGE_512K
+#define STM32_MSIRANGE STM32_MSIRANGE_4M
#define STM32_SW STM32_SW_MSI
#define STM32_PLLSRC STM32_PLLSRC_HSI16
-#define STM32_PLLMUL_VALUE 4
-#define STM32_PLLDIV_VALUE 2
+#define STM32_PLLMUL_VALUE 3
+#define STM32_PLLDIV_VALUE 4
#define STM32_HPRE STM32_HPRE_DIV1
#define STM32_PPRE1 STM32_PPRE1_DIV1
#define STM32_PPRE2 STM32_PPRE2_DIV1
#define STM32_MCOSEL STM32_MCOSEL_NOCLOCK
#define STM32_MCOPRE STM32_MCOPRE_DIV1
-#define STM32_RTCSEL STM32_RTCSEL_LSI
+#define STM32_RTCSEL STM32_RTCSEL_NOCLOCK
#define STM32_RTCPRE STM32_RTCPRE_DIV2
#define STM32_USART2SEL STM32_USART2SEL_APB
#define STM32_LPUART1SEL STM32_LPUART1SEL_APB
diff --git a/dogs.c b/dogs.c
index a2d3baf..65a34e7 100644
--- a/dogs.c
+++ b/dogs.c
@@ -136,7 +136,7 @@ void dogs_init_display()
CS_LOW;
dogs_reset();
CS_HIGH;
- chThdSleepMilliseconds(100);
+ chThdSleepS(TIME_MS2I(100) / 64);
CS_LOW;
dogs_set_scroll_line(0);
dogs_set_segdir(true);
@@ -146,7 +146,7 @@ void dogs_init_display()
dogs_set_bias(true);
dogs_set_power(0x07);
dogs_set_vlcd_ratio(7);
- dogs_set_contrast(0x10);
+ dogs_set_contrast(12);
dogs_set_advanced(0x83);
dogs_set_sleep(false);
CS_HIGH;
@@ -187,12 +187,22 @@ void dogs_flush()
void draw_pixel(int x, int y, bool state)
{
+ if (x < 0 || y < 0 || x >= DISP_WIDTH || y >= DISP_HEIGHT)
+ return;
if (state)
dogs_buffer[y / 8 * DISP_WIDTH + x] |= (1 << (y % 8));
else
dogs_buffer[y / 8 * DISP_WIDTH + x] &= ~(1 << (y % 8));
}
+void draw_rect(int x, int y, int w, int h)
+{
+ for (int i = 0; i < w; i++) {
+ for (int j = 0; j < h; j++)
+ draw_pixel(x + i, y + j, true);
+ }
+}
+
void draw_bitmap(int x, int y, const unsigned char *buffer)
{
// Prepare source information
diff --git a/dogs.h b/dogs.h
index d30c6fa..c165979 100644
--- a/dogs.h
+++ b/dogs.h
@@ -22,6 +22,7 @@ void dogs_clear();
void dogs_flush();
void draw_pixel(int x, int y, bool state);
+void draw_rect(int x, int y, int w, int h);
void draw_bitmap(int x, int y, const unsigned char *buffer);
void draw_number(int x, int y, int number);
diff --git a/main.c b/main.c
index ffd5d3f..bd938d3 100644
--- a/main.c
+++ b/main.c
@@ -21,7 +21,9 @@
* - Can read buttons through PAL (through interrupts now)
* - Use ADC to read Vintref, print to screen in mV
* - Sleep mode via WFI, saves ~0.5mA (we're running around 1.1mA)
- * - Run at 512kHz, only use HSI for ADC: 360uA
+ * - Run at 512kHz, only use HSI for ADC: 360uA (jumpy)
+ * - Drop to 1.2V Vcore (range 3), enable low-V detector: 375uA (steady) (440uA at 1MHz)
+ * - Run at 4MHz, drop to low-power run/sleep @ 64kHz for idle: 375uA (also lowered contrast)
*/
static volatile bool adc_is_complete = false;
@@ -67,7 +69,7 @@ static int readVddmv()
return 3000 * /* CAL */ *((adcsample_t *)0x1FF80078) / reading;
}
-THD_WORKING_AREA(waThread2, 96);
+THD_WORKING_AREA(waThread2, 128);
THD_FUNCTION(Thread2, arg)
{
(void)arg;
@@ -86,32 +88,51 @@ THD_FUNCTION(Thread2, arg)
0b11000000,
};
+ int t1x = DISP_WIDTH, t1o = 30;
- int x = 0, y = 0;
+ int py = DISP_HEIGHT / 2 - 4;
+ int vy = 0;
int counter = 0;
int mv = readVddmv();
while (1) {
- chThdSleepMilliseconds(100);
-
- unsigned char b = button_state;
- if ((b & (BUTTON_JOYUR | BUTTON_JOYUL)) == (BUTTON_JOYUR | BUTTON_JOYUL))
- y--;
- else if ((b & (BUTTON_JOYUR | BUTTON_JOYDR)) == (BUTTON_JOYUR | BUTTON_JOYDR))
- x++;
- else if ((b & (BUTTON_JOYDR | BUTTON_JOYDL)) == (BUTTON_JOYDR | BUTTON_JOYDL))
- y++;
- else if ((b & (BUTTON_JOYDL | BUTTON_JOYUL)) == (BUTTON_JOYDL | BUTTON_JOYUL))
- x--;
+ //systime_t old_time = chVTGetSystemTimeX();
+
+ if (py > 0) {
+ py += vy;
+ if (vy > -4)
+ vy--;
+ } else if (py < 0) {
+ py = 0;
+ }
- if (++counter == 50) {
- counter = 0;
- mv = readVddmv();
+ if (button_state & BUTTON_2) {
+ vy = 5;
+ if (py <= 0)
+ py = 1;
}
dogs_clear();
- draw_bitmap(x, y, testbitmap);
+
+ draw_rect(t1x, 0, 4, t1o - 12);
+ draw_rect(t1x, t1o + 12, 4, DISP_HEIGHT - t1o + 12);
+
+ draw_bitmap(4, py, testbitmap);
+
draw_number(0, 50, mv);
dogs_flush();
+
+
+
+ if (++counter == 50) {
+ counter = 0;
+ mv = !(PWR->CSR & PWR_CSR_PVDO) ? readVddmv() : 1;
+ }
+ t1x -= 2;
+ if (t1x <= -5)
+ t1x = DISP_WIDTH;
+
+ //chThdSleepUntilS(chTimeAddX(old_time, TIME_MS2I(100) / 32));
+ chThdSleepS(TIME_MS2I(100) / 64);
}
}
@@ -125,6 +146,7 @@ int main(void)
chSysInit();
RCC->CR &= ~RCC_CR_HSION;
+ PWR->CR |= PWR_CR_LPSDSR;
buttons_init();