summaryrefslogtreecommitdiff
path: root/olsndot
diff options
context:
space:
mode:
authorjaseg <git@jaseg.net>2017-05-30 19:32:49 +0200
committerjaseg <git@jaseg.net>2017-05-30 19:32:49 +0200
commitff0ba8e4dfc9dbdb25acfc43c3e72af8aa098aca (patch)
tree6fe2a49ae4933a567e4e36b01f79b575bc296cce /olsndot
parente7a9304cc739b3487f3b8ec76efdcf09771cd0ab (diff)
downloadolsndot-ff0ba8e4dfc9dbdb25acfc43c3e72af8aa098aca.tar.gz
olsndot-ff0ba8e4dfc9dbdb25acfc43c3e72af8aa098aca.tar.bz2
olsndot-ff0ba8e4dfc9dbdb25acfc43c3e72af8aa098aca.zip
fw: Basic dimming working
Diffstat (limited to 'olsndot')
-rw-r--r--olsndot/firmware/main.c111
1 files changed, 101 insertions, 10 deletions
diff --git a/olsndot/firmware/main.c b/olsndot/firmware/main.c
index 4e26200..e4b3935 100644
--- a/olsndot/firmware/main.c
+++ b/olsndot/firmware/main.c
@@ -7,6 +7,11 @@
* Part number: STM32F030F4C6
*/
+#define NBITS 12
+void do_transpose(void);
+uint32_t brightness[8];
+volatile uint8_t brightness_by_bit[NBITS];
+
int main(void) {
RCC->CR |= RCC_CR_HSEON;
while (!(RCC->CR&RCC_CR_HSERDY));
@@ -74,7 +79,7 @@ int main(void) {
TIM1->SMCR = 0;
TIM1->DIER = 0;
- TIM1->PSC = 4; // debug
+ TIM1->PSC = 1; // debug
/* CH2 - clear/!MR, CH3 - strobe/STCP */
TIM1->CCR2 = 1;
TIM1->RCR = 0;
@@ -92,16 +97,100 @@ int main(void) {
TIM1->EGR |= TIM_EGR_UG;
- for (;;) {
- GPIOA->ODR ^= GPIO_ODR_6;
- LL_mDelay(1);
+ while (42) {
+ /*
+ for (uint8_t i=0; i<8; i++) {
+ brightness[1] = brightness[5] = i;
+ brightness[2] = brightness[6] = 0;
+ brightness[3] = brightness[7] = 0;
+ do_transpose();
+ LL_mDelay(500);
+ }
+ for (uint8_t i=0; i<8; i++) {
+ brightness[1] = brightness[5] = 0;
+ brightness[2] = brightness[6] = i;
+ brightness[3] = brightness[7] = 0;
+ do_transpose();
+ LL_mDelay(500);
+ }
+ for (uint8_t i=0; i<8; i++) {
+ brightness[1] = brightness[5] = 0;
+ brightness[2] = brightness[6] = 0;
+ brightness[3] = brightness[7] = i;
+ do_transpose();
+ LL_mDelay(500);
+ }
+ for (uint8_t i=0; i<8; i++) {
+ brightness[1] = brightness[5] = i;
+ brightness[2] = brightness[6] = i;
+ brightness[3] = brightness[7] = i;
+ do_transpose();
+ LL_mDelay(500);
+ }
+ }
+ {
+ */
+ for (uint32_t i=0; i<6; i++) {
+ for (uint32_t j=0; j<(1<<NBITS); j++) {
+ GPIOA->ODR ^= GPIO_ODR_6;
+ switch (i) {
+ case 0:
+ brightness[1] = brightness[5] = (1<<NBITS)-1;
+ brightness[2] = brightness[6] = 0;
+ brightness[3] = brightness[7] = j;
+ break;
+ case 1:
+ brightness[1] = brightness[5] = (1<<NBITS)-1-j;
+ brightness[2] = brightness[6] = 0;
+ brightness[3] = brightness[7] = (1<<NBITS)-1;
+ break;
+ case 2:
+ brightness[1] = brightness[5] = 0;
+ brightness[2] = brightness[6] = j;
+ brightness[3] = brightness[7] = (1<<NBITS)-1;
+ break;
+ case 3:
+ brightness[1] = brightness[5] = 0;
+ brightness[2] = brightness[6] = (1<<NBITS)-1;
+ brightness[3] = brightness[7] = (1<<NBITS)-1-j;
+ break;
+ case 4:
+ brightness[1] = brightness[5] = j;
+ brightness[2] = brightness[6] = (1<<NBITS)-1;
+ brightness[3] = brightness[7] = 0;
+ break;
+ case 5:
+ brightness[1] = brightness[5] = (1<<NBITS)-1;
+ brightness[2] = brightness[6] = (1<<NBITS)-1-j;
+ brightness[3] = brightness[7] = 0;
+ break;
+ }
+ do_transpose();
+ LL_mDelay(1);
+ }
+ }
}
}
-#define NBITS 4
-uint8_t brightness_by_bit[NBITS] = {
- 0x11, 0x22, 0x44, 0x88
-};
+uint32_t brightness[8] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
+volatile uint8_t brightness_by_bit[NBITS] = { 0 };
+
+void do_transpose(void) {
+ for (uint32_t i=0; i<NBITS; i++) {
+ uint8_t bv = 0;
+ uint32_t mask = 1<<i;
+ for (uint32_t j=0; j<8; j++) {
+ if (brightness[j] & mask)
+ bv |= 1<<j;
+ }
+ brightness_by_bit[i] = bv;
+ }
+}
+
+/*
+ * 460ns
+ * 720ns
+ */
/*
* 1.00us
@@ -115,12 +204,14 @@ uint8_t brightness_by_bit[NBITS] = {
*/
void TIM1_BRK_UP_TRG_COM_IRQHandler(void) {
static uint32_t idx = 0;
- idx = (idx+1)&7;
+ idx++;
+ if (idx >= NBITS)
+ idx = 0;
GPIOA->ODR ^= GPIO_ODR_4;
TIM1->CCMR1 = (4<<TIM_CCMR1_OC2M_Pos); // | TIM_CCMR1_OC2PE;
- SPI1->DR = 0x88<<8;
+ SPI1->DR = brightness_by_bit[idx]<<8;
while (SPI1->SR & SPI_SR_BSY);
const uint32_t period_base = 4; /* 1us */