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
@csrohit
csrohit / gpio_setup.c
Last active November 20, 2022 13:20
Systick with libopencm3
static void gpio_setup(void)
{
rcc_periph_clock_enable(RCC_GPIOC);
gpio_set_mode(GPIOC, GPIO_MODE_OUTPUT_2_MHZ,
GPIO_CNF_OUTPUT_PUSHPULL, GPIO13);
}
@csrohit
csrohit / baudrate_calculation.c
Created November 12, 2022 11:00
code snippets for medium blog on USART in stm32 using polling method
uint32_t baud = (uint32_t)(SystemCoreClock / baudrate);
USART1->BRR = baud;
@csrohit
csrohit / led.c
Created November 4, 2022 13:45
Supporting code for Systick medium article
void led_init()
{
RCC->APB2ENR |= RCC_APB2ENR_IOPCEN;
GPIOC->CRH = 0x02 << ((13 - 8) << 2);
}
void led_on()
{
GPIOC->BSRR = 1 << 13;
}
@csrohit
csrohit / declaration.c
Created September 4, 2022 17:26
Multithreading in zephyr rtos
#define MY_STACK_SIZE 512
static void thread1_handler(void *, void *, void *);
static void thread2_handler(void *, void *, void *);
K_THREAD_STACK_DEFINE(stack1, MY_STACK_SIZE);
struct k_thread thread1_data;
K_THREAD_STACK_DEFINE(stack2, MY_STACK_SIZE);
struct k_thread thread2_data;
// enable interrupt on button for rising edge
ret = gpio_pin_interrupt_configure_dt(&button, GPIO_INT_EDGE_RISING);
if (ret != 0) {
printk("Error %d: failed to configure interrupt on %s pin %d\n",
ret, button.port->name, button.pin);
return;
}
// initialize callback structure for button interrupt
gpio_init_callback(&button_cb, button_pressed, BIT(button.pin));
@csrohit
csrohit / check_device_ready.c
Last active August 20, 2022 07:27
Device tree overlay for stm32 to configure PA0 as output led
if (!device_is_ready(spec.port))
{
return;
}
var dbRef = firebase.database().ref();
const userRef = dbRef.child('Users');
var container = document.getElementById('container');
userRef.on("child_added", snap => {
let user = snap.val();
let li = document.createElement('li');
li.innerHTML = `<i class="fa fa-user-circle" aria-hidden="true"></i>${user.name}`
container.appendChild(li);
li.addEventListener('click', launchChatWindow);
var dbRef = firebase.database().ref();
const usrRef = dbRef.child('Messages/XuqOxUbSWAPIC763Sxtc6WepFfd2')
const container = document.getElementById('chat-container');
let messages = new Object;
usrRef.on("child_added", snap => {
//* sender is sending as well as receiving messages
let sender = snap.val();
// create a heading with name of the sender in it
const div = document.createElement('div');
// fetch information of the sender
#include <Arduino.h>
#include <U8x8lib.h>
#include <lmic.h>
#include <hal/hal.h>
#include <SPI.h>
// Credentials
static const PROGMEM u1_t NWKSKEY[16] ={ 0xD9, 0x87, 0x45, 0xEC, 0xD6, 0x69, 0x1B, 0x2F, 0x1A, 0x32, 0x34, 0xEB, 0xFE, 0x74, 0x03, 0x91 };
static const PROGMEM u1_t APPSKEY[16] ={ 0x1E, 0x2C, 0x65, 0xCD, 0x5D, 0xE9, 0x1E, 0xE3, 0xC7, 0x3A, 0x1A, 0x6C, 0x3C, 0x10, 0xB4, 0xCA } ;