fixed memory bug in u8x8_d_bitmap.c

This commit is contained in:
olikraus 2017-11-19 11:36:58 +01:00
parent de3d02e59e
commit e30600288e
2 changed files with 47 additions and 1 deletions

View File

@ -298,6 +298,48 @@ uint16_t getADC(uint8_t ch)
return ADC1->DR;
}
void scanADC(uint8_t ch, uint16_t cnt, uint8_t *buf)
{
RCC->AHBENR |= RCC_AHBENR_DMAEN; /* enable DMA clock */
__NOP(); __NOP(); /* extra delay for clock stabilization required? */
/* defaults:
- 8 Bit access --> ok
- read from peripheral --> ok
- none-circular mode --> ok
- no increment mode --> will be changed below
*/
DMA1_Channel1->CNDTR = cnt; /* one data, then repeat (circular mode) */
DMA1_Channel1->CPAR = (uint32_t)&(ADC1->DR); /* source value */
DMA1_Channel1->CMAR = (uint32_t)buf; /* destination memory */
DMA1_CSELR->CSELR &= ~DMA_CSELR_C1S; /* 0000: select ADC for DMA CH 1 (this is reset default) */
DMA1_Channel1->CCR |= DMA_CCR_MINC; /* increment memory */
DMA1_Channel1->CCR |= DMA_CCR_EN; /* enable */
/*
detect rising edge on external trigger (ADC_CFGR1_EXTEN_0)
recive trigger from TIM2 (ADC_CFGR1_EXTSEL_1)
8 Bit resolution (ADC_CFGR1_RES_1)
Use DMA one shot mode and enable DMA (ADC_CFGR1_DMAEN)
Once DMA is finished, it will disable continues mode (ADC_CFGR1_CONT)
*/
ADC1->CFGR1 = ADC_CFGR1_EXTEN_0
| ADC_CFGR1_EXTSEL_1
| ADC_CFGR1_RES_1
| ADC_CFGR1_CONT
| ADC_CFGR1_DMAEN;
}
/*=======================================================================*/
void initTIM(void)
@ -339,6 +381,7 @@ void initTIM(void)
/* so, update request by couter over/underflow remains */
//TIM2->CR1 |= TIM_CR1_URS; /* only udf/ovf generae events */
TIM2->CR2 |= TIM_CR2_MMS_1; /* Update event for TRGO */
TIM2->ARR = 4096; /* total cycle count */
TIM2->CCR2 = 1024; /* duty cycle */

View File

@ -50,12 +50,15 @@ uint8_t u8x8_bitmap_SetSize(u8x8_bitmap_t *b, uint16_t pixel_width, uint16_t pix
b->u8g2_buf = NULL;
return 0;
}
//printf("pixel size: %d %d\n", b->pixel_width, b->pixel_height);
//printf("tile size: %d %d\n", b->tile_width, b->tile_height);
return 1;
}
void u8x8_bitmap_DrawTiles(u8x8_bitmap_t *b, uint16_t tx, uint16_t ty, uint8_t tile_cnt, uint8_t *tile_ptr)
{
uint8_t *dest_ptr = b->u8x8_buf;
//printf("tile pos: %d %d, cnt=%d\n", tx, ty, tile_cnt);
if ( dest_ptr == NULL )
return;
dest_ptr += ty*b->pixel_width;
@ -279,7 +282,7 @@ static uint8_t u8x8_d_bitmap_chain(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, v
/* connect the bitmap to an existing u8g2 or u8x8 object */
uint8_t u8x8_ConnectBitmapToU8x8(u8x8_t *u8x8)
{
if ( u8x8_SetBitmapDeviceSize(u8x8, u8x8_GetCols(u8x8), u8x8_GetRows(u8x8)) == 0 )
if ( u8x8_SetBitmapDeviceSize(u8x8, u8x8_GetCols(u8x8)*8, u8x8_GetRows(u8x8)*8) == 0 )
return 0;
u8x8_bitmap.u8x8_bitmap_display_old_cb = u8x8->display_cb;
u8x8->display_cb = u8x8_d_bitmap_chain;