Skip to content

Instantly share code, notes, and snippets.

View csrohit's full-sized avatar
🏠
Working from home

Rohit Nimkar csrohit

🏠
Working from home
View GitHub Profile
This gist if for article on Timer3 Output Compare
This gist is for timer delay
@csrohit
csrohit / address.c
Last active January 15, 2024 16:20
scan-adc
/* Set peripheral address as ADC data register */
DMA1_Channel1->CPAR = (uint32_t)&ADC1->DR;
/* Set memory address as adc_value buffer */
DMA1_Channel1->CMAR = (uint32_t)adc_value;
/* Set number of transfers */
DMA1_Channel1->CNDTR = 2U;
@csrohit
csrohit / shadow-matrix.c
Created January 1, 2024 19:24
Projective Shadows in OpenGL
void setShadowMatrix(GLfloat *destMat, float *lightPos, double *plane)
{
GLfloat dot;
// dot product of plane and light position
dot = plane[0] * lightPos[0] + plane[1] * lightPos[1] + plane[2] * lightPos[2];
// first column
destMat[0] = dot - plane[0] * lightPos[0];
destMat[4] = 0.0f - lightPos[0] * plane[1];
@csrohit
csrohit / init_adc.c
Last active February 19, 2023 06:53
supporting gist for adc medium article
void init_adc(void){
/* Set ADC prescalar*/
RCC->CFGR |= RCC_CFGR_ADCPRE_DIV6;
/* Enable clock for ADC & PortA */
RCC->APB2ENR |= RCC_APB2ENR_ADC1EN | RCC_APB2ENR_IOPAEN;
/* COnfigure PA0 in analog input mode */
GPIOA->CRL &= ~(GPIO_CRL_CNF0 | GPIO_CRL_MODE0);
@csrohit
csrohit / ahb2-div.c
Last active January 9, 2023 17:23
Supporting gist for clock configuration article
RCC->CFGR |= RCC_CFGR_PPRE1_2;
RCC->CFGR |= RCC_CFGR_PLLXTPRE_HSE;
@csrohit
csrohit / circular-interrupt.c
Last active October 30, 2023 10:22
Supporting gist for circular DMA operation
// enable circular mode
DMA1_Channel4->CCR |= DMA_CCR_CIRC;
// enable interrpt after full transfer
DMA1_Channel4->CCR |= DMA_CCR_TCIE;
@csrohit
csrohit / constructor.cpp
Last active December 21, 2022 09:11
Supporting code for memory mapped objects
USART()
{
if (this == reinterpret_cast<USART *>(USART1))
{
// enable clock for GPIOA and USART1
RCC->APB2ENR |= RCC_APB2ENR_USART1EN | RCC_APB2ENR_IOPAEN;
// reset pin configurations for PA9 and PA10
GPIOA->CRH &= ~(GPIO_CRH_MODE10 | GPIO_CRH_MODE9 | GPIO_CRH_CNF10 | GPIO_CRH_CNF9);
@csrohit
csrohit / Linker scripts
Last active December 2, 2022 13:24
Supporting code for article on linker script
swswsw
@csrohit
csrohit / code_size_optimization
Last active December 1, 2022 09:03
Gist for supporting article on optimising code size
We couldn’t find that file to show.