CMOS-based intelligent neural interface device for optogenetics